public async Task SetStatusAsync_IdAndBooleanAsParameters() { var hiveSectionId = 3; var storeContext = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); storeContext.Setup(c => c.Sections).ReturnsAsyncEntitySet(_sections); var service = new HiveSectionService(storeContext.Object, userContext.Object); await service.SetStatusAsync(hiveSectionId, true); await service.SetStatusAsync(hiveSectionId, false); }
public async Task SetStatusAsync_IdPresent_RequestedHiveStatusChanged() { 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); await service.SetStatusAsync(1, false); var hive = await service.GetHiveSectionAsync(1); Assert.False(hive.IsDeleted); }
public async void SetStatusAsync_NotExistedEntityIdentifier_CustomExceptionThrows([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture) { Configure(context, fixture); var id = 0; await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.SetStatusAsync(id, false)); }
public async void SetStatusAsync_EntityHasFlagIsDeletedFalseSetTrue_SuccsessfulChange([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture) { Configure(context, fixture); _section[0].IsDeleted = false; await service.SetStatusAsync(_section[0].Id, true); _section[0].IsDeleted.Should().Be(true); }
public async Task SetStatusAsync_RequestedResourceNotFoundExceptionThrown([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service) { context.Setup(s => s.Sections).ReturnsEntitySet(new StoreHiveSection[] { }); var exception = await Assert.ThrowsAsync <RequestedResourceNotFoundException>( () => service.SetStatusAsync(0, false)); Assert.Equal(typeof(RequestedResourceNotFoundException), exception.GetType()); }
public async Task SetStatusAsync_HiveSection_RequestedResourceNotFoundException(IFixture fixture) { var storeSectionHives = fixture.CreateMany <StoreHiveSection>(0).ToArray(); _context.Setup(s => s.Sections).ReturnsEntitySet(storeSectionHives); var service = new HiveSectionService(_context.Object, _userContext.Object); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.SetStatusAsync(1, true)); }
public async Task Setstatus_NotFound_Entity_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveSectionService hiveSectionService, int hiveSectionId, bool deletedStatus) { var listEntity = fixture.CreateMany <StoreHiveSection>(0).ToList(); context.Setup(c => c.Sections).ReturnsEntitySet(listEntity); var ex = await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => hiveSectionService.SetStatusAsync(hiveSectionId, deletedStatus)); Assert.Equal(typeof(RequestedResourceNotFoundException), ex.GetType()); }
public void SetStatusAsync_NoSectionWithSuchIdTest(int id, bool status) { 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.SetStatusAsync(id, status)); }
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()); }
public async Task SetStatusAsync_PassesHiveSectionIdAndDeleteStatus_ExpectsRequestedResourceNotFoundException( [Frozen] Mock <IProductStoreHiveContext> contextMock, HiveSectionService hiveSectionService, IFixture fixture) { var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToArray(); contextMock.Setup(c => c.Sections).ReturnsEntitySet(storeHiveSections); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => hiveSectionService.SetStatusAsync(123, false)); }
public async Task SetStatus_ValidData_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveSectionService hiveSectionService, bool deletedStatus) { var listEntity = fixture.CreateMany <StoreHiveSection>(13).ToList(); context.Setup(c => c.Sections).ReturnsEntitySet(listEntity); await hiveSectionService.SetStatusAsync(listEntity[0].Id, deletedStatus); var hiveSectionAfter = await hiveSectionService.GetHiveSectionAsync(listEntity[0].Id); Assert.Equal(hiveSectionAfter.IsDeleted, deletedStatus); }
public async Task SetStatusAsync_UpdateNonExistentSection_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.SetStatusAsync(1, true); }); }
public async Task SetStatusAsync_SetDeletedInFirstItem([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture) { fixture.Behaviors.Add(new OmitOnRecursionBehavior()); var sections = fixture.CreateMany <StoreHiveSection>(10).ToList(); sections.First().IsDeleted = false; context.Setup(s => s.Sections).ReturnsEntitySet(sections); await service.SetStatusAsync(sections.First().Id, true); Assert.True(sections.First().IsDeleted); }
public async Task SetStatus_RequestedResourceNotFoundException( [Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture) { var section = fixture.Create <StoreHiveSection>(); context.Setup(x => x.Sections).ReturnsEntitySet(new StoreHiveSection[] { section }); Func <Task> act = async() => await service.SetStatusAsync(0, true); act.Should().Throw <RequestedResourceNotFoundException>(); }
public async Task SetStatus_SetFalse([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture) { var hiveSections = fixture.CreateMany <StoreHiveSection>(5).ToArray(); context.Setup(x => x.Sections).ReturnsEntitySet(hiveSections); await service.SetStatusAsync(hiveSections[2].Id, false); var hiveSection = await service.GetHiveSectionAsync(hiveSections[2].Id); hiveSection.IsDeleted.Should().BeFalse(); }
public async Task SetStatusAsync_IdAndBooleanAsParameters_NotExistedHiveId_ThrownException() { var hiveSectionId = 10; var storeContext = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); storeContext.Setup(c => c.Sections).ReturnsAsyncEntitySet(_sections); var service = new HiveSectionService(storeContext.Object, userContext.Object); await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.SetStatusAsync(hiveSectionId, true)); }
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 SetStatusAsync_PassesHiveSectionIdAndDeleteStatus_ExpectsSuccessfullEqualityAssertion( [Frozen] Mock <IProductStoreHiveContext> contextMock, HiveSectionService hiveSectionService, IFixture fixture) { bool actualDeletedStatus = false; var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToArray(); contextMock.Setup(c => c.Sections).ReturnsEntitySet(storeHiveSections); await hiveSectionService.SetStatusAsync(storeHiveSections[2].Id, actualDeletedStatus); var expectedDeletedStatus = (await hiveSectionService.GetHiveSectionAsync(storeHiveSections[2].Id)).IsDeleted; Assert.Equal(expectedDeletedStatus, actualDeletedStatus); }
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 void SetStatusToHiveSectionSuccessfull() { 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 HiveSectionService(productContext.Object, userContext.Object); await service.SetStatusAsync(1, true); var hiveSection = await service.GetHiveSectionAsync(1); Assert.True(hiveSection.IsDeleted); }
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 SetStatusAsync_SetHiveSectionStatus(int sectionId, bool hiveSectionStatusBefor, bool hiveSectionStatusAfter) { var storeHiveSection = new StoreHiveSection(); storeHiveSection.Id = sectionId; storeHiveSection.IsDeleted = hiveSectionStatusBefor; Assert.Equal(hiveSectionStatusBefor, storeHiveSection.IsDeleted); var storeSectionHives = new[] { storeHiveSection }; _context.Setup(s => s.Sections).ReturnsEntitySet(storeSectionHives); var service = new HiveSectionService(_context.Object, _userContext.Object); await service.SetStatusAsync(sectionId, hiveSectionStatusAfter); Assert.Equal(hiveSectionStatusAfter, storeHiveSection.IsDeleted); }
public async Task SetStatusAsync_SuccessfulTest(int id, bool status) { 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); await service.SetStatusAsync(id, status); var hive = await service.GetHiveSectionAsync(id); Assert.Equal(status, hive.IsDeleted); }
public async Task SetStatusAsync_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.SetStatusAsync(3, false)); }
public async Task SetStatusAsync_ChangeStatusFromTrueToTrue_StatusIsTrue() { 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.SetStatusAsync(0, true); var section = await service.GetHiveSectionAsync(0); Assert.True(section.IsDeleted); }