public async Task DeleteHiveSectionAsync_IdPresent_RequestedHiveDeleted() { var mockUserContext = new Mock <IUserContext>(); var mockHiveContext = new Mock <IProductStoreHiveContext>(); List <StoreHiveSection> sectionList = new List <StoreHiveSection>() { new StoreHiveSection() { Id = 1, IsDeleted = true }, new StoreHiveSection() { Id = 2 } }; mockHiveContext.Setup(c => c.Sections).ReturnsEntitySet(sectionList); var service = new HiveSectionService(mockHiveContext.Object, mockUserContext.Object); await service.DeleteHiveSectionAsync(1); var hiveSections = await service.GetHiveSectionsAsync(); Assert.DoesNotContain(hiveSections, h => h.Id == 1); }
public async void DeleteHiveSectionAsync_ExistedIdentifierFlagIsDeletedFalse_CustomExceptionThrows([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture) { Configure(context, fixture); var id = _section[0].Id; _section[0].IsDeleted = false; await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => service.DeleteHiveSectionAsync(id)); }
public async Task DeleteHiveSectionAsync_RequestedResourceNotFoundExceptionThrown([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service) { context.Setup(s => s.Sections).ReturnsEntitySet(new StoreHiveSection[] { }); var exception = await Assert.ThrowsAsync <RequestedResourceNotFoundException>( () => service.DeleteHiveSectionAsync(0)); Assert.Equal(typeof(RequestedResourceNotFoundException), exception.GetType()); }
public void DeleteHiveSectionAsync_NoSectionWithSuchIdTest(int id) { var context = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>()); var service = new HiveSectionService(context.Object, userContext.Object); Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => await service.DeleteHiveSectionAsync(id)); }
public async void DeleteHiveSectionAsync_ExistedIdentifierFlagIsDeletedTrue_SuccessfulDeleting([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture) { Configure(context, fixture); var id = _section[0].Id; _section[0].IsDeleted = true; await service.DeleteHiveSectionAsync(id); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.GetHiveSectionAsync(id)); }
public async Task DeleteHiveSectionAsync_DeleteNonExistentSection_ExceptionThrown() { var context = new Mock <IProductStoreHiveContext>(); context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>()); var service = new HiveSectionService(context.Object, new UserContext()); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => { await service.DeleteHiveSectionAsync(0); }); }
public async Task DeleteHiveSectionAsync_PassesHiveSectionId_ThrowsRequestedResourceHasConflictException( [Frozen] Mock <IProductStoreHiveContext> contextMock, HiveSectionService hiveSectionService, IFixture fixture) { var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToList(); contextMock.Setup(c => c.Sections).ReturnsEntitySet(storeHiveSections); storeHiveSections[0].IsDeleted = false; await Assert.ThrowsAsync <RequestedResourceHasConflictException>( () => hiveSectionService.DeleteHiveSectionAsync(storeHiveSections[0].Id)); }
public async Task DeleteHiveSectionAsync_IdAsParametr_NotExistedHiveId_ThrownException() { var hiveSectionId = 10; var storeContext = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); storeContext.Setup(c => c.Hives).ReturnsAsyncEntitySet(_hives); storeContext.Setup(c => c.Sections).ReturnsAsyncEntitySet(_sections); var service = new HiveSectionService(storeContext.Object, userContext.Object); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.DeleteHiveSectionAsync(hiveSectionId)); }
public async Task DeleteHiveSectionAsync_PassesHiveSectionId_ExpectsThatCollectionDoesNotContainDeletedHiveSection( [Frozen] Mock <IProductStoreHiveContext> contextMock, HiveSectionService hiveSectionService, IFixture fixture) { var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToList(); contextMock.Setup(c => c.Sections).ReturnsEntitySet(storeHiveSections); var deletedHiveSection = storeHiveSections[1]; await hiveSectionService.DeleteHiveSectionAsync(storeHiveSections[1].Id); Assert.DoesNotContain(deletedHiveSection, storeHiveSections); }
public async Task DeleteHiveSection_Successfuly_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveSectionService hiveSectionService) { var listEntity = fixture.CreateMany <StoreHiveSection>(13).ToList(); var listHiveEntity = new List <StoreHive>(); context.Setup(x => x.Hives).ReturnsEntitySet(listHiveEntity); context.Setup(x => x.Sections).ReturnsEntitySet(listEntity); await hiveSectionService.SetStatusAsync(listEntity[0].Id, true); await hiveSectionService.DeleteHiveSectionAsync(listEntity[0].Id); var hiveSections = await hiveSectionService.GetHiveSectionsAsync(); Assert.Equal(12, hiveSections.Count); }
public async Task DeleteHiveSection_RequestedResourceHasConflictException( [Frozen] Mock <IProductStoreHiveContext> contex, HiveSectionService service, IFixture fixture) { var hiveSections = fixture.CreateMany <StoreHiveSection>(5).ToList(); var hives = fixture.CreateMany <StoreHive>(3).ToArray(); contex.Setup(x => x.Hives).ReturnsEntitySet(hives); contex.Setup(x => x.Sections).ReturnsEntitySet(hiveSections); await service.SetStatusAsync(hiveSections[0].Id, false); Func <Task> act = async() => await service.DeleteHiveSectionAsync(hiveSections[0].Id); act.Should().Throw <RequestedResourceHasConflictException>(); }
public async Task DeleteHiveSection_SetFiveElement_DeleteOne_FourReturned( [Frozen] Mock <IProductStoreHiveContext> contex, HiveSectionService service, IFixture fixture) { var hiveSections = fixture.CreateMany <StoreHiveSection>(5).ToList(); var hives = fixture.CreateMany <StoreHive>(3).ToArray(); contex.Setup(x => x.Hives).ReturnsEntitySet(hives); contex.Setup(x => x.Sections).ReturnsEntitySet(hiveSections); await service.SetStatusAsync(hiveSections[0].Id, true); await service.DeleteHiveSectionAsync(hiveSections[0].Id); var result = await service.GetHiveSectionsAsync(); result.Count.Should().Be(4); }
public async Task DeleteHiveSectionAsync_HiveSectionId_RequestedResourceHasConflictException( [Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture) { var hiveSectionId = 1; var dbHiveSections = fixture.CreateMany <StoreHiveSection>(1).ToList(); dbHiveSections[0].Id = hiveSectionId; dbHiveSections[0].IsDeleted = false; context.Setup(s => s.Sections).ReturnsEntitySet(dbHiveSections); await Assert.ThrowsAsync <RequestedResourceHasConflictException>( () => service.DeleteHiveSectionAsync(hiveSectionId)); }
public async Task DeleteHiveSectionAsync_SuccessfulTest(int id) { var context = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>() { new StoreHiveSection() { Id = 1, IsDeleted = true } }); var service = new HiveSectionService(context.Object, userContext.Object); await service.DeleteHiveSectionAsync(id); var sections = await service.GetHiveSectionsAsync(); Assert.Empty(sections); }
public async Task DeleteHiveSectionAsync_IdAsParametr_StatusIsDeletedTrue() { var list = new StoreHiveSection[1] { new StoreHiveSection { Id = 3, Code = "SECT3", IsDeleted = true } }; var hiveSectionId = list[0].Id; var storeContext = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); storeContext.Setup(c => c.Sections).ReturnsAsyncEntitySet(list); var service = new HiveSectionService(storeContext.Object, userContext.Object); await service.DeleteHiveSectionAsync(hiveSectionId); }
public async Task DeleteHiveSectionAsync_StatusIsNotDeleted_RequestedResourceHasConflictThrown() { var mockUserContext = new Mock <IUserContext>(); var mockHiveContext = new Mock <IProductStoreHiveContext>(); List <StoreHiveSection> hiveSectionsList = new List <StoreHiveSection>() { new StoreHiveSection() { Id = 1, IsDeleted = false, Code = "aa" }, new StoreHiveSection() { Id = 2, Code = "bb" } }; mockHiveContext.Setup(c => c.Sections).ReturnsEntitySet(hiveSectionsList); var service = new HiveSectionService(mockHiveContext.Object, mockUserContext.Object); Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => service.DeleteHiveSectionAsync(1)); }
public async Task DeleteHiveSectionAsync_IdNotPresent_RequestedResourceNotFoundExceptionThrown() { var mockUserContext = new Mock <IUserContext>(); var mockHiveContext = new Mock <IProductStoreHiveContext>(); List <StoreHiveSection> hiveSectionsList = new List <StoreHiveSection>() { new StoreHiveSection() { Id = 1, Code = "aa" }, new StoreHiveSection() { Id = 2, Code = "bb" } }; mockHiveContext.Setup(c => c.Sections).ReturnsEntitySet(hiveSectionsList); var service = new HiveSectionService(mockHiveContext.Object, mockUserContext.Object); Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.DeleteHiveSectionAsync(3)); }
public async Task DeleteHiveSectionAsync_SectionWithTrueStatus_SectionDeleted() { var sections = new List <StoreHiveSection>() { new StoreHiveSection() { Id = 0, IsDeleted = true }, new StoreHiveSection() { Id = 1, IsDeleted = false } }; var context = new Mock <IProductStoreHiveContext>(); context.Setup(c => c.Sections).ReturnsEntitySet(sections); var service = new HiveSectionService(context.Object, new UserContext()); await service.DeleteHiveSectionAsync(0); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.GetHiveSectionAsync(0)); }
public void DeleteHiveSectionAsync_IsDeletedFalseTest(int id) { var context = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>() { new StoreHiveSection() { Id = 1, IsDeleted = false } }); var service = new HiveSectionService(context.Object, userContext.Object); Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() => await service.DeleteHiveSectionAsync(id)); }
public async Task DeleteHive_DeletingHiveWithUndeletedStatus_ExceptionThrown( [Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service) { var hiveSection = new StoreHiveSection { Id = 1, IsDeleted = false }; context.Setup(c => c.Sections).ReturnsAsyncEntitySet(new[] { hiveSection }); await Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() => await service.DeleteHiveSectionAsync(hiveSection.Id)); }
public async Task DeleteHiveSection_DeletingHiveSectionWithUnexistedId_ExceptionThrown( [Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service) { context.Setup(c => c.Sections).ReturnsAsyncEntitySet(new StoreHiveSection[0]); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => await service.DeleteHiveSectionAsync(1)); }
public async Task DeleteHiveSection_ConflictException_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveSectionService hiveSectionService) { var listEntity = fixture.CreateMany <StoreHiveSection>(13).ToList(); context.Setup(x => x.Sections).ReturnsEntitySet(listEntity); await hiveSectionService.SetStatusAsync(listEntity[0].Id, false); var ex = await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => hiveSectionService.DeleteHiveSectionAsync(listEntity[0].Id)); Assert.Equal(typeof(RequestedResourceHasConflictException), ex.GetType()); }