public async Task SetStatusAsync_IdAndBooleanAsParameters() { var hiveId = 3; var storeContext = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); storeContext.Setup(c => c.Hives).ReturnsAsyncEntitySet(_hives); var service = new HiveService(storeContext.Object, userContext.Object); await service.SetStatusAsync(hiveId, true); await service.SetStatusAsync(hiveId, false); }
public async void SetStatusAsync_NotExistedEntityIdentifier_CustomExceptionThrows([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture) { Configure(context, fixture); var id = 0; await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.SetStatusAsync(id, false)); }
public async Task SetStatusAsync_IdPresent_RequestedHiveStatusChanged() { var mockUserContext = new Mock <IUserContext>(); var mockHiveContext = new Mock <IProductStoreHiveContext>(); List <StoreHive> hiveList = new List <StoreHive>() { new StoreHive() { Id = 1, IsDeleted = true }, new StoreHive() { Id = 2 } }; mockHiveContext.Setup(c => c.Hives).ReturnsEntitySet(hiveList); var service = new HiveService(mockHiveContext.Object, mockUserContext.Object); await service.SetStatusAsync(1, false); var hive = await service.GetHiveAsync(1); Assert.False(hive.IsDeleted); }
public async void SetStatusAsync_EntityHasFlagIsDeletedFalseSetTrue_SuccsessfulChange([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture) { Configure(context, fixture); _hive[0].IsDeleted = false; await service.SetStatusAsync(_hive[0].Id, true); _hive[0].IsDeleted.Should().Be(true); }
public async Task SetStatusAsync_RequestedResourceNotFoundExceptionThrown([Frozen] Mock <IProductStoreHiveContext> context, HiveService service) { context.Setup(s => s.Hives).ReturnsEntitySet(new StoreHive[] { }); var exception = await Assert.ThrowsAsync <RequestedResourceNotFoundException>( () => service.SetStatusAsync(0, false)); Assert.Equal(typeof(RequestedResourceNotFoundException), exception.GetType()); }
public async Task SetStatusAsync_Hive_RequestedResourceNotFoundException(IFixture fixture) { var storeHives = fixture.CreateMany <StoreHive>(0).ToArray(); _context.Setup(s => s.Hives).ReturnsEntitySet(storeHives); var service = new HiveService(_context.Object, _userContext.Object); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.SetStatusAsync(1, true)); }
public void SetStatusAsync_NoHiveWithSuchIdTest(int id, bool status) { var context = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>()); var service = new HiveService(context.Object, userContext.Object); Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => await service.SetStatusAsync(id, status)); }
public async Task SetStatusAsync_SetDeletedInFirstItem([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture) { fixture.Behaviors.Add(new OmitOnRecursionBehavior()); var hives = fixture.CreateMany <StoreHive>(10).ToList(); hives.First().IsDeleted = false; context.Setup(s => s.Hives).ReturnsEntitySet(hives); context.Setup(s => s.Sections).ReturnsEntitySet(new List <StoreHiveSection>()); await service.SetStatusAsync(hives.First().Id, true); }
public async Task DeleteHive_ConflictException_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveService hiveService) { var listEntity = fixture.CreateMany <StoreHive>(13).ToList(); context.Setup(x => x.Hives).ReturnsEntitySet(listEntity); await hiveService.SetStatusAsync(listEntity[0].Id, false); var ex = await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => hiveService.DeleteHiveAsync(listEntity[0].Id)); Assert.Equal(typeof(RequestedResourceHasConflictException), ex.GetType()); }
public async Task SetStatusAsync_PassesHiveIdAndDeleteStatus_ExpectsRequestedResourceNotFoundException( [Frozen] Mock <IProductStoreHiveContext> contextMock, HiveService hiveService, IFixture fixture) { var storeHives = fixture.CreateMany <StoreHive>(3).ToArray(); contextMock.Setup(c => c.Hives).ReturnsEntitySet(storeHives); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => hiveService.SetStatusAsync(123, false)); }
public async Task SetStatusAsync_UpdateNonExistentHive_ExceptionThrown() { var context = new Mock <IProductStoreHiveContext>(); context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>()); var service = new HiveService(context.Object, new UserContext()); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => { await service.SetStatusAsync(1, true); }); }
public async Task SetStatus_ValidData_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveService hiveService, bool deletedStatus) { var listEntity = fixture.CreateMany <StoreHive>(13).ToList(); context.Setup(c => c.Hives).ReturnsEntitySet(listEntity); await hiveService.SetStatusAsync(listEntity[0].Id, deletedStatus); var hiveAfter = await hiveService.GetHiveAsync(listEntity[0].Id); Assert.Equal(hiveAfter.IsDeleted, deletedStatus); }
public async Task SetStatus_RequestedResourceNotFoundException( [Frozen] Mock <IProductStoreHiveContext> contex, HiveService service, IFixture fixture) { var collection = fixture.CreateMany <StoreHive>(5).ToArray(); contex.Setup(x => x.Hives).ReturnsEntitySet(collection); Func <Task> act = async() => await service.SetStatusAsync(0, true); act.Should().Throw <RequestedResourceNotFoundException>(); }
public async Task SetStatusAsync_IdAndBooleanAsParameters_NotExistedHiveId_ThrownException() { var hiveId = 10; var storeContext = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); storeContext.Setup(c => c.Hives).ReturnsAsyncEntitySet(_hives); var service = new HiveService(storeContext.Object, userContext.Object); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.SetStatusAsync(hiveId, true)); }
public async Task DeleteHive_Successfuly_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveService hiveService) { var listEntity = fixture.CreateMany <StoreHive>(13).ToList(); context.Setup(x => x.Hives).ReturnsEntitySet(listEntity); context.Setup(x => x.Sections).ReturnsEntitySet(new List <StoreHiveSection>()); await hiveService.SetStatusAsync(listEntity[0].Id, true); await hiveService.DeleteHiveAsync(listEntity[0].Id); var hives = await hiveService.GetHivesAsync(); Assert.Equal(12, hives.Count); }
public async Task SetStatusAsync_ChangeStatusFromFalseToFalse_StatusIsFalse([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture) { fixture.Behaviors.Remove(new ThrowingRecursionBehavior()); fixture.Behaviors.Add(new OmitOnRecursionBehavior()); var hives = fixture.CreateMany <StoreHive>(2).ToArray(); hives[1].IsDeleted = true; context.Setup(c => c.Hives).ReturnsEntitySet(hives); await service.SetStatusAsync(hives[1].Id, false); var hive = await service.GetHiveAsync(hives[1].Id); hive.IsDeleted.Should().Be(false); }
public async Task SetStatus_SetFalse( [Frozen] Mock <IProductStoreHiveContext> contex, HiveService service, IFixture fixture) { var collection = fixture.CreateMany <StoreHive>(5).ToArray(); contex.Setup(x => x.Hives).ReturnsEntitySet(collection); await service.SetStatusAsync(collection[0].Id, false); var result = await service.GetHiveAsync(collection[0].Id); result.IsDeleted.Should().BeFalse(); }
public async Task DeleteHive_RequestedResourceHasConflictException( [Frozen] Mock <IProductStoreHiveContext> contex, HiveService service, IFixture fixture) { var collection = fixture.CreateMany <StoreHive>(5).ToList(); contex.Setup(x => x.Hives).ReturnsEntitySet(collection); contex.Setup(x => x.Sections).ReturnsEntitySet(new List <StoreHiveSection>()); await service.SetStatusAsync(collection[0].Id, false); Func <Task> act = async() => await service.DeleteHiveAsync(collection[0].Id); act.Should().Throw <RequestedResourceHasConflictException>(); }
public async Task SetStatusAsync_PassesHiveIdAndDeleteStatus_ExpectsSuccessfullEqualityAssertion( [Frozen] Mock <IProductStoreHiveContext> contextMock, HiveService hiveService, IFixture fixture) { bool actualDeletedStatus = false; var storeHives = fixture.CreateMany <StoreHive>(3).ToArray(); contextMock.Setup(c => c.Hives).ReturnsEntitySet(storeHives); await hiveService.SetStatusAsync(storeHives[2].Id, actualDeletedStatus); var expectedDeletedStatus = (await hiveService.GetHiveAsync(storeHives[2].Id)).IsDeleted; Assert.Equal(expectedDeletedStatus, actualDeletedStatus); }
public async void SetStatusToHiveSuccessfull() { var productContext = new Mock <IProductStoreHiveContext>(); productContext.Setup(p => p.Hives).ReturnsEntitySet(new List <StoreHive>()); var userContext = new Mock <IUserContext>(); userContext.Setup(u => u.UserId).Returns(1); var service = new HiveService(productContext.Object, userContext.Object); await service.SetStatusAsync(1, true); var hive = await service.GetHiveAsync(1); Assert.True(hive.IsDeleted); }
public async Task DeleteHive_SetFiveElement_DeleteOne_FourReturned( [Frozen] Mock <IProductStoreHiveContext> contex, HiveService service, IFixture fixture) { var collection = fixture.CreateMany <StoreHive>(5).ToList(); contex.Setup(x => x.Hives).ReturnsEntitySet(collection); contex.Setup(x => x.Sections).ReturnsEntitySet(new List <StoreHiveSection>()); await service.SetStatusAsync(collection[0].Id, true); await service.DeleteHiveAsync(collection[0].Id); var result = await service.GetHivesAsync(); result.Count.Should().Be(4); }
public async Task SetStatusAsync_SetHiveStatus(int hiveId, bool hiveStatusBefor, bool hiveStatusAfter) { var storeHive = new StoreHive(); storeHive.Id = hiveId; storeHive.IsDeleted = hiveStatusBefor; Assert.Equal(hiveStatusBefor, storeHive.IsDeleted); var storeHives = new[] { storeHive }; _context.Setup(s => s.Hives).ReturnsEntitySet(storeHives); var service = new HiveService(_context.Object, _userContext.Object); await service.SetStatusAsync(hiveId, hiveStatusAfter); Assert.Equal(hiveStatusAfter, storeHive.IsDeleted); }
public async Task SetStatusAsync_SuccessfulTest(int id, bool status) { var context = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>() { new StoreHive() { Id = 1, IsDeleted = false } }); var service = new HiveService(context.Object, userContext.Object); await service.SetStatusAsync(id, status); var hive = await service.GetHiveAsync(id); Assert.Equal(status, hive.IsDeleted); }
public async Task SetStatusAsync_IdNotPresent_RequestedResourceNotFoundExceptionThrown() { var mockUserContext = new Mock <IUserContext>(); var mockHiveContext = new Mock <IProductStoreHiveContext>(); List <StoreHive> hiveList = new List <StoreHive>() { new StoreHive() { Id = 1 }, new StoreHive() { Id = 2 } }; mockHiveContext.Setup(c => c.Hives).ReturnsEntitySet(hiveList); var service = new HiveService(mockHiveContext.Object, mockUserContext.Object); Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.SetStatusAsync(3, false)); }
public async Task SetStatusAsync_ChangeStatusFromTrueToTrue_StatusIsTrue() { var hives = new List <StoreHive>() { new StoreHive() { Id = 0, IsDeleted = true }, new StoreHive() { Id = 1, IsDeleted = false } }; var context = new Mock <IProductStoreHiveContext>(); context.Setup(c => c.Hives).ReturnsEntitySet(hives); var service = new HiveService(context.Object, new UserContext()); await service.SetStatusAsync(0, true); var hive = await service.GetHiveAsync(0); Assert.True(hive.IsDeleted); }
public async Task Setstatus_HasConflictException_Entity_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveService hiveService, int hiveId, bool deletedStatus) { var listEntity = fixture.CreateMany <StoreHive>(0).ToList(); context.Setup(c => c.Hives).ReturnsEntitySet(listEntity); var ex = await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => hiveService.SetStatusAsync(hiveId, deletedStatus)); Assert.Equal(typeof(RequestedResourceHasConflictException), ex.GetType()); }