public async Task ClaimLock_Given_Scope_Gives_ReturnItem() { var createItem = new TestItemBare { Value = "x" }; var item = await _table.CreateAndReturnAsync(createItem); Assert.IsNotNull(item); bool?lockSuccess = null; using (var scope = CreateStandardScope()) { try { var lockedItem = await _table.SearchSingleAndLockWhereAsync("Id=@Id", new { Id = item.Id }); FulcrumAssert.IsNotNull(lockedItem); lockSuccess = true; scope.Complete(); } catch (Exception) { lockSuccess = false; } } Assert.IsNotNull(lockSuccess); Assert.IsTrue(lockSuccess); }
public async Task Update_NotFound_Async() { var updateItem = new TestItemBare(); updateItem.InitializeWithDataForTesting(TypeOfTestDataEnum.Default); await CrudStorage.UpdateAsync(CrudHelper.CreateNewId <TId>(), updateItem); Assert.Fail("Expected an exception"); }
public async Task CreateAndReturn_Async() { var initialItem = new TestItemBare(); initialItem.InitializeWithDataForTesting(TypeOfTestDataEnum.Default); var createdItem = await CrdStorage.CreateAndReturnAsync(initialItem); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(createdItem); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(initialItem, createdItem); }
public async Task TestWithDefaultId() { var item = new TestItemBare(); item.InitializeWithDataForTesting(TypeOfTestDataEnum.Default); await ExpectContractExceptionAsync(async() => await _implementation.CreateWithSpecifiedIdAsync(Guid.Empty, item), "CreateWithSpecifiedIdAsync(Guid.Empty, item)"); await ExpectContractExceptionAsync(async() => await _implementation.CreateWithSpecifiedIdAndReturnAsync(Guid.NewGuid(), null), "CreateWithSpecifiedIdAndReturnAsync(Guid.Empty, item)"); }
public async Task MessageGetsThrough() { var message = new TestItemBare(); message.InitializeWithDataForTesting(TypeOfTestDataEnum.Variant1); await Queue.AddMessageAsync(message); var result = await Queue.GetOneMessageNoBlockAsync(); Assert.IsNotNull(result); Assert.AreEqual(message, result); }
public async Task CreateAndReturn_Read_Etag_Async() { var initialItem = new TestItemBare(); initialItem.InitializeWithDataForTesting(TypeOfTestDataEnum.Default); var createdItem = await CrdStorage.CreateAndReturnAsync(initialItem); Assert.IsNotNull(createdItem); Assert.AreNotEqual(createdItem.Id, default); Assert.IsNotNull(createdItem.Etag); Assert.AreEqual(initialItem, createdItem); }
public async Task Create_Read_Async() { var initialItem = new TestItemBare(); initialItem.InitializeWithDataForTesting(TypeOfTestDataEnum.Default); var id = await CrdStorage.CreateAsync(initialItem); var createdItem = await CrdStorage.ReadAsync(id); Assert.IsNotNull(createdItem); Assert.AreEqual(initialItem, createdItem); }
public async Task ClaimLock_Given_ItemExists_Gives_ReturnItem() { var createItem = new TestItemBare { Value = "x" }; var item = await _table.CreateAndReturnAsync(createItem); Assert.IsNotNull(item); var lockedItem = await _table.SearchSingleAndLockWhereAsync("Id=@Id", new { Id = item.Id }); Assert.IsNotNull(lockedItem); }
public async Task ClaimLock_Given_AlreadyLocked_Gives_FulcrumTryAgainException() { var createItem = new TestItemBare { Value = "x" }; var item = await _table.CreateAndReturnAsync(createItem); Assert.IsNotNull(item); bool?lock2Success = null; var claimLock1Success = new ManualResetEvent(false); var hasTriedToClaimLock2 = new ManualResetEvent(false); var thread1 = ThreadHelper.FireAndForget(async() => { using (var scope = CreateStandardScope()) { var lockedItem = await _table.SearchSingleAndLockWhereAsync("Id=@Id", new { Id = item.Id }); FulcrumAssert.IsNotNull(lockedItem); claimLock1Success.Set(); FulcrumAssert.IsTrue(hasTriedToClaimLock2.WaitOne(TimeSpan.FromSeconds(1)), CodeLocation.AsString()); scope.Complete(); } }); var thread2 = ThreadHelper.FireAndForget(async() => { FulcrumAssert.IsTrue(claimLock1Success.WaitOne(TimeSpan.FromSeconds(1))); using (var scope = CreateStandardScope()) { try { var lockedItem = await _table.SearchSingleAndLockWhereAsync("Id=@Id", new { Id = item.Id }); FulcrumAssert.IsNotNull(lockedItem); lock2Success = true; scope.Complete(); } catch (FulcrumTryAgainException) { lock2Success = false; } } hasTriedToClaimLock2.Set(); }); Assert.IsTrue(thread2.Join(TimeSpan.FromSeconds(5))); Assert.IsNotNull(lock2Success); Assert.IsFalse(lock2Success); Assert.IsTrue(thread1.Join(TimeSpan.FromSeconds(1))); }
public async Task ClearQueue() { var message = new TestItemBare(); message.InitializeWithDataForTesting(TypeOfTestDataEnum.Variant1); await Queue.AddMessageAsync(message); await Queue.ClearAsync(); var getTask = Queue.GetOneMessageNoBlockAsync(); await Task.Delay(TimeSpan.FromMilliseconds(100)); Assert.IsTrue(getTask.IsCompleted, "Expected the method to finish quickly."); Assert.IsNull(await getTask); }
public async Task Delete_Async() { var initialItem = new TestItemBare(); initialItem.InitializeWithDataForTesting(TypeOfTestDataEnum.Default); var id = await CrdStorage.CreateAsync(initialItem); await CrdStorage.ReadAsync(id); await CrdStorage.DeleteAsync(id); var item = await CrdStorage.ReadAsync(id); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNull(item); }
public async Task PeekAndGet() { var message = new TestItemBare(); message.InitializeWithDataForTesting(TypeOfTestDataEnum.Variant1); await Queue.AddMessageAsync(message); var result = await Queue.PeekNoBlockAsync(); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(result); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(message, result); result = await Queue.GetOneMessageNoBlockAsync(); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(result); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(message, result); }