private void ReadAnyValue(ref JReader r, TestValue <ReaderAction> value) { var av = r.Any(); Assert.Equal(value.Type, av.Type); switch (value.Type) { case ValueType.Bool: Assert.Equal(value.BoolValue, av.BoolValue); break; case ValueType.Number: Assert.Equal(value.NumberValue, av.NumberValue); break; case ValueType.String: Assert.Equal(value.StringValue, av.StringValue.ToString()); break; case ValueType.Array: ReadArray(ref r, av.ArrayValue, value); break; case ValueType.Object: ReadObject(ref r, av.ObjectValue, value); break; default: break; } }
public void Equals_FalseForNull() { var x = new TestValue("Foo", 42); x.Equals((TestValue)null).Should().BeFalse(); x.Equals((object)null).Should().BeFalse(); }
public void Equals_FalseForDifferentTypes() { var x = new TestValue("Foo", 42); var y = new TestValue2("Foo", 42); x.Equals(y).Should().BeFalse(); }
public void GetHashCode_NotEqualForDifferentComponents(string xFoo, int xBar, string yFoo, int yBar) { var x = new TestValue(xFoo, xBar); var y = new TestValue(yFoo, yBar); x.GetHashCode().Should().NotBe(y.GetHashCode()); }
public void GetHashCode_HandlesPropertyNulls() { var x = new TestValue(null, 42); var y = new TestValue("Foo", 42); x.GetHashCode().Should().NotBe(y.GetHashCode()); }
public void UpdateRewetTestBaseTest() { var viewModel = new InkoRewetEditViewModel { TestPerson = "Hans", TestValueId = -1, TestSheetId = 1, ProductionCodeTime = new TimeSpan(12, 34, 0), ProductionCodeDay = 123, FPDry = 20.0, FPWet = 20.2, Notes = new List <TestNote> { new TestNote { ErrorCodeId = 1, Id = 1, Message = "Testnote" } } }; var testValueReturnedFromDb = new TestValue { TestSheetId = 1, CreatedDateTime = new DateTime(2016, 1, 2), LastEditedDateTime = new DateTime(2016, 1, 2), CreatedPerson = "Fritz", LastEditedPerson = "Fritz", DayInYearOfArticleCreation = 123, ArticleTestType = ArticleType.IncontinencePad, TestValueNote = new List <TestValueNote> { new TestValueNote { ErrorId = 1, Message = "Testnote" } }, IncontinencePadTestValue = new IncontinencePadTestValue { IncontinencePadTime = new TimeSpan(11, 11, 0), TestType = TestTypeIncontinencePad.RewetFree } }; var testSheetDataFromDb = GetTestSheetTestData(); var productionOrderDataFromDb = GetProductionOrderTestData(); var babyDiaperBll = MockHelperBll.GetTestBllForSavingAndUpdating(testSheetDataFromDb, productionOrderDataFromDb, testValueReturnedFromDb); var testServiceHelper = MockHelperTestServiceHelper.GetTestServiceHelperForUpdating(); var target = new InkoRewetServiceHelper(new NLogLoggerFactory()) { TestBll = babyDiaperBll, TestServiceHelper = testServiceHelper }; var actual = target.UpdateRewetTest(viewModel); Assert.Equal(testValueReturnedFromDb, actual); Assert.Equal(20, actual.IncontinencePadTestValue.RewetFreeDryValue); Assert.Equal(20.2, actual.IncontinencePadTestValue.RewetFreeWetValue); Assert.Equal(0.2, actual.IncontinencePadTestValue.RewetFreeDifference, 2); Assert.Equal("Hans", actual.LastEditedPerson); Assert.Equal("Fritz", actual.CreatedPerson); Assert.NotEqual(new DateTime(2016, 1, 2), actual.LastEditedDateTime); }
public void GetHashCode_EqualForTwoSame() { var x = new TestValue("Foo", 42); var y = new TestValue("Foo", 42); x.GetHashCode().Should().Be(y.GetHashCode()); }
public void ToJsonPatch_Update_Complex_Success() { var path = "Test"; var expectedPath = $"/{path.ToCamelCase()}"; var expectedNewValue = new TestValue { StringValue = "My new complex value", IntValue = 12345 }; var changes = ChangeSet.Create( ChangePath.Create(path), new ChangeValue { Action = ChangeAction.Update, NewValue = expectedNewValue }); var patch = changes.ToJsonPatch(); Assert.Single(patch); var operation = patch[0]; Assert.Equal(OperationType.Replace, operation.OperationType); Assert.Equal(expectedPath, operation.path); Assert.Equal(expectedNewValue, operation.value); }
// POST api/values /*public void Post([FromBody]string value) * { * * }*/ public async Task <List <TestValue> > Post() { string result = await Request.Content.ReadAsStringAsync(); List <TestValue> newList = new List <TestValue>(); dynamic jobj = JsonConvert.DeserializeObject(result); string action = jobj.ACTION; if (action.Equals("CREATE")) { foreach (dynamic jdata in jobj.DATA) { TestValue @TestValue = new TestValue(); @TestValue.NAZIV = jdata.NAZIV; @TestValue.VRIJEME = jdata.VRIJEME; db.TestValues.Add(@TestValue); db.SaveChanges(); newList.Add(@TestValue); } } return(newList); }
public void ToDashboardInfosIncontinencePadRewetTest() { var testvalue = new TestValue { ArticleTestType = ArticleType.IncontinencePad, IncontinencePadTestValue = new IncontinencePadTestValue { TestType = TestTypeIncontinencePad.RewetFree, RewetFreeRw = RwType.Better, RewetFreeDifference = 12.123 } }; var target = new LaborDashboardHelper(new NLogLoggerFactory()); var info = target.ToDashboardInfosIncontinencePad(testvalue); info.Count.Should() .Be(1); info.ToList()[0].RwType.Should() .Be(RwType.Better); info.ToList()[0].InfoKey.Should() .Be("Rewet"); info.ToList()[0].InfoValue.Should() .Be("12.12"); }
public void ToDashboardInfosBabyDiapersRetentionTest() { var testvalue = new TestValue { ArticleTestType = ArticleType.BabyDiaper, BabyDiaperTestValue = new BabyDiaperTestValue { TestType = TestTypeBabyDiaper.Retention, RetentionRw = RwType.Worse, RetentionAfterZentrifugeValue = 12.0 } }; var target = new LaborDashboardHelper(new NLogLoggerFactory()); var info = target.ToDashboardInfosBabyDiapers(testvalue); info.Count.Should() .Be(1); info.ToList()[0].RwType.Should() .Be(RwType.Worse); info.ToList()[0].InfoValue.Should() .Be("12"); info.ToList()[0].InfoKey.Should() .Be("Retention - Nach Zentrifuge (g)"); }
public void ToDashboardInfosIncontinencePadRetentionTest() { var testvalue = new TestValue { ArticleTestType = ArticleType.IncontinencePad, IncontinencePadTestValue = new IncontinencePadTestValue { TestType = TestTypeIncontinencePad.Retention, RetentionRw = RwType.Ok, RetentionEndValue = 12 } }; var target = new LaborDashboardHelper(new NLogLoggerFactory()); var info = target.ToDashboardInfosIncontinencePad(testvalue); info.Count.Should() .Be(1); info.ToList()[0].RwType.Should() .Be(RwType.Ok); info.ToList()[0].InfoKey.Should() .Be("Retention"); info.ToList()[0].InfoValue.Should() .Be("12"); }
public void ToDashboardInfosBabyDiapersRewetTest() { var testvalue = new TestValue { ArticleTestType = ArticleType.BabyDiaper, BabyDiaperTestValue = new BabyDiaperTestValue { TestType = TestTypeBabyDiaper.Rewet, Rewet140Rw = RwType.Better, Rewet140Value = 12.12345, Rewet210Value = 14.444, Rewet210Rw = RwType.Ok } }; var target = new LaborDashboardHelper(new NLogLoggerFactory()); var info = target.ToDashboardInfosBabyDiapers(testvalue); info.Count.Should() .Be(2); info.ToList()[0].RwType.Should() .Be(RwType.Better); info.ToList()[0].InfoValue.Should() .Be("12.12"); info.ToList()[0].InfoKey.Should() .Be("Rewet - 140 ml"); info.ToList()[1].RwType.Should() .Be(RwType.Ok); info.ToList()[1].InfoValue.Should() .Be("14.44"); info.ToList()[1].InfoKey.Should() .Be("Rewet - 210 ml"); }
public void TestLocalFileStore_Json() { InitializeLocalStorage(); var rootPath = Path.Combine( Directory.GetCurrentDirectory(), "test-data-store"); //if (Directory.Exists(rootPath)) Directory.Delete(rootPath, true); var testKey = new TestValue.Key(accountId: Guid.NewGuid()); var testValueA = new TestValue( accountId: testKey.AccountId.Value, message: "Hello, world!"); var testValueB = new TestValue( accountId: testKey.AccountId.Value, message: "Kthx, world!"); var dataStore = new FileStoreDataStore <TestValue.Key, TestValue>( fileStore: new LocalFileStore(rootPath: rootPath), serializer: new JsonSerializer(), keyMap: "test-values/{AccountId}", fileExtension: ".json"); TestDataStore( dataStore, testKey, testValueA, testValueB); }
public void TestLocalFileStore_GZip_Json() { var rootPath = Path.Combine( Directory.GetCurrentDirectory(), "test-data-store"); //if (Directory.Exists(rootPath)) Directory.Delete(rootPath, true); var testKey = new TestValue.Key(accountId: Guid.NewGuid()); var testValueA = new TestValue( accountId: testKey.AccountId.Value, message: "Hello, world!"); var testValueB = new TestValue( accountId: testKey.AccountId.Value, message: "Kthx, world!"); var dataStore = new FileStoreDataStore <TestValue.Key, TestValue>( fileStore: new LocalFileStore(rootPath: rootPath), serializer: new JsonSerializer($"{JsonOptions.Default}"), compressor: new GZipCompressor(), keyMap: "test-values/{AccountId}", fileExtension: ".json.gzip"); UniversalIntegrationTest.TestDataStore( dataStore, testKey, testValueA, testValueB); }
/// <summary> /// Converts the notes from the viewmodel to the dbmodel. /// Deletes notes which were deleted in the view /// adds new notes to the db /// updates notes /// </summary> /// <param name="vmNotes">the List of Notes from the ViewModel</param> /// <param name="testValue">the testvalue where the notes are for</param> /// <returns>the production code</returns> public void UpdateNotes(IList <TestNote> vmNotes, TestValue testValue) { if (vmNotes.IsNull()) { vmNotes = new List <TestNote>(); } foreach (var note in vmNotes.Where(vmNote => vmNote.ErrorCodeId == 0) .Select(vmNote => testValue.TestValueNote.FirstOrDefault(n => n.TestValueNoteId == vmNote.Id)) .Where(note => note.IsNotNull())) { testValue.TestValueNote.Remove(note); TestBll.DeleteNote(note.TestValueNoteId); } foreach (var note in testValue.TestValueNote) { foreach (var vmNote in vmNotes.Where(vmNote => note.TestValueNoteId == vmNote.Id)) { note.Message = vmNote.Message; note.ErrorId = vmNote.ErrorCodeId; } } foreach (var vmNote in vmNotes.Where(n => (n.Id == 0) && (n.ErrorCodeId != 0))) { testValue.TestValueNote.Add(new TestValueNote { ErrorId = vmNote.ErrorCodeId, Message = vmNote.Message, TestValue = testValue }); } }
public void DeleteTest() { var deletedTestValue = new TestValue { TestValueId = 1 }; var inkoRetentionServiceHelper = MockHelperTestServiceHelper.GetInkoRetentionServiceHelper( null ); var testBll = MockHelperBll.GetBabyDiaperBllForDelete( deletedTestValue ); var target = new InkoRetentionService(new NLogLoggerFactory()) { InkoRetentionServiceHelper = inkoRetentionServiceHelper, TestBll = testBll }; var actual = target.Delete(1); Assert.Equal(1, actual.TestValueId); }
public ConvertResult Convert(IConvertContext context) { var convertResult = new List <TestValue>(); using (var sr = new StreamReader(@"yaml/test.yml", Encoding.UTF8)) { var yamlStream = new YamlStream(); yamlStream.Load(sr); var values = yamlStream.Documents[0].RootNode as YamlSequenceNode; foreach (YamlMappingNode v in values) { var v1 = v.Children[new YamlScalarNode("v1")].ToString(); var v2 = v.Children[new YamlScalarNode("v2")].ToString(); var testValue = new TestValue() { V1 = uint.Parse(v1), V2 = uint.Parse(v2) }; convertResult.Add(testValue); } } var testValues = new TestValueAll(); testValues.TestValues.AddRange(convertResult); ProtobufWriter.WriteTo(testValues, "testValues"); return(ConvertResult.Success); }
private IPushKeyValueEntryCommand CreateSut(string key = null, TestValue value = null) { return(_fixture.Build <BusinessLogic.Common.Commands.PushKeyValueEntryCommand>() .With(m => m.Key, key ?? _fixture.Create <string>()) .With(m => m.Value, value ?? BuildTestValue()) .Create()); }
public void Lz4Benchmark() { // R2 has some strange very slow read perf on this data when count is small // R3 is balanced, good compr and fast enough var count = itemCount; var values = new TestValue[count]; for (int i = 0; i < count; i++) { values[i] = new TestValue() { // Dec = (((decimal)i + 1M / (decimal)(i + 1))), Dbl = (double)i + 1 / (double)(i + 1), //Dbl1 = (double)i + 1 / (double)(i + 1), Num = i, Num1 = i, Num2 = i, Str = i.ToString(), //Str1 = ((double)i + 1 / (double)(i + 1)).ToString(), Boo = i % 2 == 0 }; } var bufferLen = 1000_000; var originalPtr = Marshal.AllocHGlobal(bufferLen); var compressedPtr = Marshal.AllocHGlobal(bufferLen); var decompressedPtr = Marshal.AllocHGlobal(bufferLen); var originalDB = new DirectBuffer(bufferLen, originalPtr); var compressedDB = new DirectBuffer(bufferLen, compressedPtr); var decompressedDB = new DirectBuffer(bufferLen, decompressedPtr); var originalLen = BinarySerializer.Write(values, originalDB, default, SerializationFormat.Json);
public void TestGoogleDrive() { var testKey = new TestValue.Key(accountId: Guid.NewGuid()); var testValueA = new TestValue( accountId: testKey.AccountId.Value, message: "Hello, world!"); var testValueB = new TestValue( accountId: testKey.AccountId.Value, message: "Kthx, world!"); var dataStore = new FileStoreDataStore <TestValue.Key, TestValue>( fileStore: new GoogleDriveFileStore( applicationName: GetConfig("ApplicationName"), serviceAccountEmail: GetConfig("ServiceAccountEmail"), serviceAccountKey: GetConfig("ServiceAccountKey"), grantAccessToEmails: GetConfig("GrantAccessToEmails")), serializer: new JsonSerializer($"{JsonOptions.Default}"), keyMap: "test-values/{AccountId}", fileExtension: ".json"); TestDataStore( dataStore, testKey, testValueA, testValueB); }
private object TestRun(Type classType, object instance, TestValue tv) { List <object> temp = new List <object>(); object res = null; for (int i = 0; i < tv.parameterDatas.Count; i++) { temp.Add(tv.parameterDatas[i].setValue); } tv.tempParameter = temp.ToArray(); try { res = HDJ.Framework.Utils.ReflectionUtils.InvokMethod(classType, instance, tv.methodeName, ref tv.tempParameter); if (res != null) { if (tv.resultWant.setValue.Equals(res)) { tv.testState = TestState.Pass; tv.exceptionInfo = ""; } else { tv.testState = TestState.NoPass; } } }catch (Exception e) { Debug.LogError(e); tv.exceptionInfo = e.ToString(); } return(res); }
public void TestPofUniformSparseArray() { // perform the test twice, once with references disable, once with them enabled for (bool isRefEnabled = false; ;) { TestValue tv = CreateTestValue(isRefEnabled); Binary bin = Serialize(tv, isRefEnabled); IPofValue root = PofValueParser.Parse(bin, GetPofContext(isRefEnabled)); IPofValue pv = root.GetChild(5); Assert.IsTrue(pv is PofUniformSparseArray); Assert.AreEqual(pv.GetChild(2).GetValue(), "two"); Assert.AreEqual(pv.GetChild(4).GetValue(), "four"); if (isRefEnabled) { break; } pv.GetChild(1).SetValue("jedan"); pv.GetChild(3).SetValue("tri"); pv.GetChild(4).SetValue("cetiri"); pv.GetChild(5).SetValue("pet"); Binary binModified = root.ApplyChanges(); TestValue tvModified = (TestValue)Deserialize(binModified); ILongArray arr = tvModified.m_uniformSparseArray; Assert.AreEqual(arr[1], "jedan"); Assert.AreEqual(arr[2], "two"); Assert.AreEqual(arr[3], "tri"); Assert.AreEqual(arr[4], "cetiri"); Assert.AreEqual(arr[5], "pet"); isRefEnabled = true; } }
public void Add_WhenPassedNumbersStringContainingOneNumber_ReturnsProvidedNumber() { const int TestValue = 6; var result = _stringCalculator.Add(TestValue.ToString()); Assert.AreEqual(TestValue, result); }
private static void UpdateInkoRewetStDev(TestSheet testSheet, TestValue rewetTestAvg, TestValue rewetTestStDev) { var tempInko = new IncontinencePadTestValue(); var counter = 0; foreach ( var testValue in testSheet.TestValues.Where( testValue => (testValue.TestValueType == TestValueType.Single) && (testValue.IncontinencePadTestValue.TestType == TestTypeIncontinencePad.RewetFree)) ) { tempInko.RewetFreeDryValue += Math.Pow(testValue.IncontinencePadTestValue.RewetFreeDryValue - rewetTestAvg.IncontinencePadTestValue.RewetFreeDryValue, 2); tempInko.RewetFreeWetValue += Math.Pow(testValue.IncontinencePadTestValue.RewetFreeWetValue - rewetTestAvg.IncontinencePadTestValue.RewetFreeWetValue, 2); tempInko.RewetFreeDifference += Math.Pow(testValue.IncontinencePadTestValue.RewetFreeDifference - rewetTestAvg.IncontinencePadTestValue.RewetFreeDifference, 2); counter++; } if (counter < 2) { rewetTestStDev.IncontinencePadTestValue.RewetFreeDryValue = 0; rewetTestStDev.IncontinencePadTestValue.RewetFreeWetValue = 0; rewetTestStDev.IncontinencePadTestValue.RewetFreeDifference = 0; } else { counter--; rewetTestStDev.IncontinencePadTestValue.RewetFreeDryValue = Math.Sqrt(tempInko.RewetFreeDryValue / counter); rewetTestStDev.IncontinencePadTestValue.RewetFreeWetValue = Math.Sqrt(tempInko.RewetFreeWetValue / counter); rewetTestStDev.IncontinencePadTestValue.RewetFreeDifference = Math.Sqrt(tempInko.RewetFreeDifference / counter); } }
public void UpdateNotesUpdateExistingNoteTest() { var notes = new List <TestNote> { new TestNote { ErrorCodeId = 1, Id = 1, Message = "New Message" } }; var testValue = new TestValue { TestValueNote = new List <TestValueNote> { new TestValueNote { ErrorId = 2, TestValueNoteId = 1, Message = "Old Message" } } }; var testServiceHelper = new TestServiceHelper(new NLogLoggerFactory()); testServiceHelper.UpdateNotes(notes, testValue); Assert.Equal(1, testValue.TestValueNote.Count); Assert.Equal("New Message", testValue.TestValueNote.First() .Message); Assert.Equal(1, testValue.TestValueNote.First() .ErrorId); }
public void UpdateNotesDeleteNoteTest() { var notes = new List <TestNote> { new TestNote { ErrorCodeId = 0, Id = 1, Message = "TestMessage" } }; var testValue = new TestValue { TestValueNote = new List <TestValueNote> { new TestValueNote { ErrorId = 2, TestValueNoteId = 1, Message = "TestMessage" } } }; var testBll = MockHelperBll.GetTestBllForDeletingNotes(); var testServiceHelper = new TestServiceHelper(new NLogLoggerFactory()) { TestBll = testBll }; testServiceHelper.UpdateNotes(notes, testValue); Assert.Equal(0, testValue.TestValueNote.Count); }
/// <summary> /// generates a list of dashboard infos which are from the testvalue of baby diaper /// </summary> /// <param name="testValue">the testvalues containing baby diapers test value</param> /// <returns>a list of dashboard infos from the testvalue</returns> public List <DashboardInfo> ToDashboardInfosBabyDiapers(TestValue testValue) { var infos = new List <DashboardInfo>(); if ((testValue.BabyDiaperTestValue.TestType == TestTypeBabyDiaper.Rewet) || (testValue.BabyDiaperTestValue.TestType == TestTypeBabyDiaper.RewetAndPenetrationTime)) { infos.Add(ToDashboardInfo("Rewet - 140 ml", Round(testValue.BabyDiaperTestValue.Rewet140Value) .ToString(CultureInfo.InvariantCulture), testValue.BabyDiaperTestValue.Rewet140Rw.GetValueOrDefault())); infos.Add(ToDashboardInfo("Rewet - 210 ml", Round(testValue.BabyDiaperTestValue.Rewet210Value) .ToString(CultureInfo.InvariantCulture), testValue .BabyDiaperTestValue.Rewet210Rw.GetValueOrDefault())); if (testValue.BabyDiaperTestValue.TestType == TestTypeBabyDiaper.RewetAndPenetrationTime) { infos.Add(ToDashboardInfo("Penetrationszeit - Zugabe 4", Round(testValue.BabyDiaperTestValue.PenetrationTimeAdditionFourth) .ToString(CultureInfo.InvariantCulture), testValue.BabyDiaperTestValue.PenetrationRwType.GetValueOrDefault())); } } else if (testValue.BabyDiaperTestValue.TestType == TestTypeBabyDiaper.Retention) { infos.Add(ToDashboardInfo("Retention - Nach Zentrifuge (g)", Round(testValue.BabyDiaperTestValue.RetentionAfterZentrifugeValue) .ToString(CultureInfo.InvariantCulture), testValue.BabyDiaperTestValue.RetentionRw.GetValueOrDefault())); } return(infos); }
public void ShouldConvertTextValueFromString(string keyValue, string displayText) { var key = new TestValue(keyValue, displayText); var converted = new TextValueTypeConverter <TestValue>().ConvertFromString(keyValue); Assert.That(converted, Is.EqualTo(key)); }
public void SetsPropertyValue() { object expected = new TestValue(); sut.Value = expected; Assert.Same(expected, ((TestType)instance).Property); }
public static void Init() { TestValue v = new TestValue(); v.a = 100; v.b = 200; v.c = 300; sField = v; }
TestValue DisjointEnsures(bool b) { Contract.Ensures(Contract.Result<TestValue>() == null || Contract.Result<TestValue>().F >= 5); if (b) return null; TestValue v = new TestValue(); v.F = 5; return v; }
public void AsTask_ReturnsACompletedTask() { var taskResult = new TestValue(); var task = taskResult.AsTask(); Assert.IsNotNull(task); Assert.AreEqual(TaskStatus.RanToCompletion, task.Status); Assert.AreSame(taskResult, task.Result); }
public void Test_HtmlExtension_ValidationResult() { var value = new TestValue(); value.SuccessMessage("Test"); this.Helper.HtmlHelper.ViewData.ModelState.AddModelError("Error", "Error"); this.Helper.HtmlHelper.ValidationResult(); Assert.AreEqual(371, this.Helper.ViewContext.Writer.ToString().Length); }
public void Test_HtmlExtension_Message() { var list = new PagedCollection<int>(new List<int>(), 1, 1, 2); var value = new TestValue(); value.SuccessMessage("Test"); this.Helper.HtmlHelper.Message(value); Assert.AreEqual(353, this.Helper.ViewContext.Writer.ToString().Length); }
public void Bind_ProducesCancelledTaskOfCompletedSourceIfBoundCancels() { var tcs = new TaskCompletionSource<TestValue>(); var source = tcs.Task; var result = source.Bind(x => TaskMonad.TaskMonad.CreateCancelled<object>()); var testValue = new TestValue(); tcs.SetResult(testValue); Assert.IsNotNull(result); Assert.AreEqual(TaskStatus.Canceled, result.Status); }
public void Bind_ProducesCancelledTaskOfCompletedSourceIfBoundThrowsTaskCancelledException() { var tcs = new TaskCompletionSource<TestValue>(); var source = tcs.Task; var result = source.Bind<TestValue, TestValue>(x => { throw new TaskCanceledException(); }); var testValue = new TestValue(); tcs.SetResult(testValue); Assert.IsNotNull(result); Assert.AreEqual(TaskStatus.Canceled, result.Status); }
public void CloneResult_ProducesACompletedTaskFromACompletedTask() { var task = new TestValue().AsTask(); var result = task.CloneResult(); Assert.IsNotNull(result); Assert.AreEqual(TaskStatus.RanToCompletion, result.Status); Assert.AreSame(task.Result, result.Result); }
public void Bind_ProducesFaultedTaskOfCompletedSourceIfBoundThrows() { var tcs = new TaskCompletionSource<TestValue>(); var source = tcs.Task; var exception = new InvalidOperationException(); var result = source.Bind<TestValue, TestValue>(x => { throw exception; }); var testValue = new TestValue(); tcs.SetResult(testValue); Assert.IsNotNull(result); Assert.AreEqual(TaskStatus.Faulted, result.Status); Assert.AreSame(exception, result.Exception.GetBaseException()); }
public void Bind_ProducesFaultedTaskOfCompletedSourceIfBoundReturnsNull() { var tcs = new TaskCompletionSource<TestValue>(); var source = tcs.Task; var result = source.Bind(x => default(Task<TestValue>)); var testValue = new TestValue(); tcs.SetResult(testValue); Assert.IsNotNull(result); Assert.AreEqual(TaskStatus.Faulted, result.Status); Assert.IsInstanceOfType(result.Exception.GetBaseException(), typeof(InvalidOperationException)); }
public void Bind_ProducesCompletedTaskOfCompletedSourceIfBoundCompletes() { var tcs = new TaskCompletionSource<TestValue>(); var source = tcs.Task; var called = false; var result = source.Bind(x => { called = true; return x.Unit(); }); var testValue = new TestValue(); tcs.SetResult(testValue); Assert.IsNotNull(result); Assert.AreEqual(TaskStatus.RanToCompletion, result.Status); Assert.AreSame(testValue, result.Result); Assert.IsTrue(called); }