public async Task UpdateHiveAsync_SuccessfulTest(int id, string name, string code, string address) { var context = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>() { new StoreHive() { Id = 1, Code = "11111" } }); var service = new HiveService(context.Object, userContext.Object); var request = new UpdateHiveRequest { Name = name, Code = code, Address = address }; await service.UpdateHiveAsync(id, request); var actualHive = await service.GetHiveAsync(id); Assert.Equal(code, actualHive.Code); }
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 Task GetHive_RequestedResourceNotFoundException( [Frozen] Mock <IProductStoreHiveContext> context, HiveService service) { context.Setup(x => x.Hives).ReturnsEntitySet(new List <StoreHive>()); Func <Task> act = async() => await service.GetHiveAsync(0); act.Should().Throw <RequestedResourceNotFoundException>(); }
public void GetHiveAsync_NoSuchHiveIdTest(int id) { 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.GetHiveAsync(id)); }
public async void GetHiveAsync_OneValidEntity_ValidEntityReturns([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture) { Configure(context, fixture); var result = await service.GetHiveAsync(_hive[0].Id); result.Code.Should().Be(_hive[0].Code); result.Name.Should().Be(_hive[0].Name); result.Address.Should().Be(_hive[0].Address); }
public async Task GetHive_ValidData_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveService hiveService) { var listEntity = fixture.CreateMany <StoreHive>(13).ToList(); context.Setup(c => c.Hives) .ReturnsEntitySet(listEntity); var foundHive = await hiveService.GetHiveAsync(listEntity[0].Id); Assert.Equal(listEntity[0].Id, foundHive.Id); }
public async void DeleteAsync_ExistedIdentifierFlagIsDeletedTrue_SuccessfulDeleting([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture) { Configure(context, fixture); var id = _hive[0].Id; _hive[0].IsDeleted = true; await service.DeleteHiveAsync(id); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.GetHiveAsync(id)); }
public async Task GetHive_ById_SetFiveElement_OneReturned( [Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture) { var collection = fixture.CreateMany <StoreHive>(5).ToArray(); context.Setup(x => x.Hives).ReturnsEntitySet(collection); var hive = await service.GetHiveAsync(collection[0].Id); hive.Id.Should().Be(collection[0].Id); }
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 GetHiveAsync_EmptyCollection_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.GetHiveAsync(0); }); }
public async Task GetHiveAsync_PassesHiveId_ThrowsRequestedResourceNotFoundException( [Frozen] Mock <IProductStoreHiveContext> contextMock, HiveService hiveService, IFixture fixture, int hiveId) { var storeHives = fixture.CreateMany <StoreHive>(0).ToArray(); contextMock.Setup(c => c.Hives).ReturnsEntitySet(storeHives); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => hiveService.GetHiveAsync(hiveId)); }
public async Task GetHiveAsync_CollectionWithTwoElements_FirstReturned([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(); context.Setup(c => c.Hives).ReturnsEntitySet(hives); var hive = await service.GetHiveAsync(hives[0].Id); hive.Id.Should().Be(hives[0].Id); }
public async Task GetHiveAsync_FirstItemReturn([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture) { fixture.Behaviors.Add(new OmitOnRecursionBehavior()); var hives = fixture.CreateMany <StoreHive>(10).ToList(); context.Setup(s => s.Hives).ReturnsEntitySet(hives); context.Setup(s => s.Sections).ReturnsEntitySet(new List <StoreHiveSection>()); var hive = await service.GetHiveAsync(hives.First().Id); Assert.Equal(hives.First().Id, hive.Id); }
public async Task GetHiveAsync_SetWithFiveElements_NotExistedIdAsParametr_ThrowException() { 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.GetHiveAsync(hiveId)); }
public async Task GetHiveAsync_SetWithFiveElements_IdAsParametr_ReturnedOneElement() { 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); var hive = await service.GetHiveAsync(hiveId); Assert.Equal(hiveId, hive.Id); }
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 GetHive_RequestWithExistedId_HiveReturned( [Frozen] Mock <IProductStoreHiveContext> context, HiveService service) { var hive = new StoreHive { Id = 1 }; context.Setup(c => c.Hives).ReturnsAsyncEntitySet(new[] { hive }); var resultHive = await service.GetHiveAsync(1); Assert.True(hive.Id == resultHive.Id); }
public async Task UpdateHive_UpdateSuccessfuly_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveService hiveService) { var listEntity = fixture.CreateMany <StoreHive>(13).ToList(); context.Setup(x => x.Hives).ReturnsEntitySet(listEntity); var createRequest = fixture.Create <UpdateHiveRequest>(); var addedHive = await hiveService.UpdateHiveAsync(listEntity[0].Id, createRequest); var hive = await hiveService.GetHiveAsync(addedHive.Id); Assert.Equal(hive.Id, listEntity[0].Id); Assert.Equal(hive.Name, createRequest.Name); Assert.Equal(hive.Address, createRequest.Address); Assert.Equal(hive.Code, createRequest.Code); }
public async Task GetHiveAsync_HiveId_RequestedResourceNotFoundException( [Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture) { // arrange var dbHives = fixture.CreateMany <StoreHive>(2).ToList(); var hiveId = dbHives[0].Id + dbHives[1].Id; context.Setup(s => s.Hives).ReturnsEntitySet(dbHives); // assert await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.GetHiveAsync(hiveId)); }
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 GetHive_Found_Entity_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveService hiveService) { var listEntity = fixture.CreateMany <StoreHive>(13).ToList(); var listSectionEntity = fixture.CreateMany <StoreHiveSection>(13).ToList(); context.Setup(c => c.Hives).ReturnsEntitySet(listEntity); context.Setup(c => c.Sections).ReturnsEntitySet(listSectionEntity); var hives = await hiveService.GetHiveAsync(listEntity[0].Id); Assert.Equal(listEntity[0].Id, hives.Id); Assert.Equal(listEntity[0].Code, hives.Code); Assert.Equal(listEntity[0].Name, hives.Name); Assert.Equal(listEntity[0].Address, hives.Address); Assert.Equal(listEntity[0].IsDeleted, hives.IsDeleted); }
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 GetHiveAsync_SuccessfulTest(int id) { var context = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>() { new StoreHive() { Id = 1 } }); var service = new HiveService(context.Object, userContext.Object); var hive = await service.GetHiveAsync(id); Assert.NotNull(hive); }
public async Task GetHiveAsync_HiveId_Hive( [Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture) { // arrange var dbHives = fixture.CreateMany <StoreHive>(2).ToList(); var hiveId = dbHives[1].Id; context.Setup(s => s.Hives).ReturnsEntitySet(dbHives); // act var hive = await service.GetHiveAsync(hiveId); // assert Assert.Equal(hiveId, hive.Id); }
public async Task GetHiveAsync_PassesCorrectHiveId_ExpectsSuccessfullEqualityAssertion( [Frozen] Mock <IProductStoreHiveContext> contextMock, HiveService hiveService, IFixture fixture) { var storeHives = fixture.CreateMany <StoreHive>(3).ToArray(); var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToArray(); contextMock.Setup(c => c.Hives).ReturnsEntitySet(storeHives); contextMock.Setup(c => c.Sections).ReturnsEntitySet(storeHiveSections); var expectedHive = storeHives[1]; var actualHive = await hiveService.GetHiveAsync(storeHives[1].Id); Assert.Equal(expectedHive.Id, actualHive.Id); Assert.Equal(expectedHive.Name, actualHive.Name); Assert.Equal(expectedHive.Address, actualHive.Address); Assert.Equal(expectedHive.Code, actualHive.Code); Assert.Equal(expectedHive.IsDeleted, actualHive.IsDeleted); }
public async Task DeleteHiveAsync_HiveId_Success( [Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture) { var hiveId = 1; var dbHives = fixture.CreateMany <StoreHive>(1).ToList(); dbHives[0].Id = hiveId; dbHives[0].IsDeleted = true; context.Setup(s => s.Hives).ReturnsEntitySet(dbHives); await service.DeleteHiveAsync(hiveId); await Assert.ThrowsAsync <RequestedResourceNotFoundException>( () => service.GetHiveAsync(hiveId)); }
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 GetHiveAsync_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.GetHiveAsync(0)); }
public async Task GetHiveAsync_CollectionWithTwoElements_FirstReturned() { var hives = new List <StoreHive>() { new StoreHive() { Id = 0 }, new StoreHive() { Id = 1 } }; var context = new Mock <IProductStoreHiveContext>(); context.Setup(c => c.Hives).ReturnsEntitySet(hives); var service = new HiveService(context.Object, new UserContext()); var hive = await service.GetHiveAsync(0); Assert.Equal(0, hive.Id); }