-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAsyncAwait.cs
113 lines (96 loc) · 3.31 KB
/
AsyncAwait.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Diagnostics;
namespace GenericConsoleApplication
{
class NoAsyncAwait
{
public long ContinuedStartMethod { get; set; }
public long FinishedWorker { get; set; }
private Stopwatch stopwatch = new Stopwatch();
public void Start()
{
stopwatch.Start();
Task.Run(new Action(Worker));
ContinuedStartMethod = stopwatch.ElapsedMilliseconds;
Thread.Sleep(500);
}
public void Worker()
{
Thread.Sleep(1000);
ContinuedStartMethod = stopwatch.ElapsedMilliseconds;
}
}
class AsyncAwait
{
Stopwatch stopwatch = new Stopwatch();
public async void Start()
{
stopwatch.Start();
await Task.Run(new Action(Worker));
}
public void Worker()
{
Thread.Sleep(1000);
}
}
#region Tests
[TestClass]
public class SimpleStratagyFactoryTests
{
#region SETUP
//[TestInitialize()]
//public void MyTestInitialize()
//{
// // Simulate initializing the factory once per app start
// SimpleStratagyFactory<AbstractProduct, ProductTypes, Dependancy>.Map(ProductTypes.TypeA, (x) => ProductA.Create(x));
// SimpleStratagyFactory<AbstractProduct, ProductTypes, Dependancy>.Map(ProductTypes.TypeB, (x) => ProductB.Create(x));
// SimpleStratagyFactory<AbstractProduct, ProductTypes, Dependancy>.Map(ProductTypes.TypeC, (x) => ProductC.Create(x));
//}
//[TestCleanup()]
//public void MyTestCleanup()
//{
// SimpleStratagyFactory<AbstractProduct, ProductTypes, Dependancy>.ClearMappings();
//}
#endregion SETUP
[TestMethod]
public void Create_WhenNoAsyncAwait_ExpectStartMethodAndWorkerAreConcurrent()
{
// Arrange
var testObject = new NoAsyncAwait();
// Act
testObject.Start();
// Assert
Assert.IsTrue(testObject.FinishedWorker > testObject.ContinuedStartMethod);
}
//[TestMethod]
//public void Create_WhenCreateWithDependancy_ExpectDependancyPassedToFactoryProducts()
//{
// // Arrange
// var factory = new SimpleStratagyFactory<AbstractProduct, ProductTypes, Dependancy>(new Dependancy());
// // Act
// var result = factory.Create(ProductTypes.TypeB);
// // Assert
// Assert.AreEqual(215, result.DoSomething());
//}
//[TestMethod]
//[ExpectedException(typeof(Exception))]
//public void Create_WhenTryCreateAnUnmappedKey_ExpectException()
//{
// // Arrange
// var factory = new SimpleStratagyFactory<AbstractProduct, ProductTypes, Dependancy>(new Dependancy());
// // Call my test cleanup to wipe out the factory mappings
// MyTestCleanup();
// // Act & Assert
// var result = factory.Create(ProductTypes.TypeA);
//}
}
#endregion Tests
}