Beispiel #1
0
        public async void GetHiveSectionAsync_NotExistedEntityIdentifier_CustomExceptionThrows([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture)
        {
            Configure(context, fixture);
            var id = 0;

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.GetHiveSectionAsync(id));
        }
        public async Task UpdateHiveSectionAsync_SuccessfulTest(int id, string name, string code)
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

            context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    Id = 1, Code = "11111"
                },
                new StoreHiveSection()
                {
                    Id = 2, Code = "11112"
                }
            });
            var service = new HiveSectionService(context.Object, userContext.Object);
            var request = new UpdateHiveSectionRequest
            {
                Name = name,
                Code = code,
            };

            await service.UpdateHiveSectionAsync(id, request);

            var actualHive = await service.GetHiveSectionAsync(id);

            Assert.Equal(code, actualHive.Code);
        }
        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);
        }
Beispiel #4
0
        public async Task GetHiveSectionAsync_RequestedResourceNotFoundExceptionThrown([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service)
        {
            context.Setup(s => s.Sections).ReturnsEntitySet(new StoreHiveSection[] { });

            var exception = await Assert.ThrowsAsync <RequestedResourceNotFoundException>(
                () => service.GetHiveSectionAsync(0));

            Assert.Equal(typeof(RequestedResourceNotFoundException), exception.GetType());
        }
Beispiel #5
0
        public async void GetHiveSectionAsync_OneValidEntity_ValidEntityReturns([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture)
        {
            Configure(context, fixture);

            var result = await service.GetHiveSectionAsync(_section[0].Id);

            result.Code.Should().Be(_section[0].Code);
            result.Name.Should().Be(_section[0].Name);
        }
Beispiel #6
0
        public async Task GetHiveSection_ValidData_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveSectionService hiveSectionService)
        {
            var listEntity = fixture.CreateMany <StoreHiveSection>(13).ToList();

            context.Setup(c => c.Sections)
            .ReturnsEntitySet(listEntity);

            var foundHive = await hiveSectionService.GetHiveSectionAsync(listEntity[0].Id);

            Assert.Equal(listEntity[0].Id, foundHive.Id);
        }
Beispiel #7
0
        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));
        }
Beispiel #8
0
        public async Task GetHiveSectionAsync_FirstItemReturn([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture)
        {
            fixture.Behaviors.Add(new OmitOnRecursionBehavior());
            var sections = fixture.CreateMany <StoreHiveSection>(10).ToList();

            context.Setup(s => s.Sections).ReturnsEntitySet(sections);

            var section = await service.GetHiveSectionAsync(sections.First().Id);

            Assert.Equal(sections.First().Id, section.Id);
        }
        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 GetHiveSection_AnyElementSet_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.GetHiveSectionAsync(10);

            act.Should().Throw <RequestedResourceNotFoundException>();
        }
        public async Task GetHiveSection_AnyElementSet_OneReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            var section = fixture.Create <StoreHiveSection>();

            context.Setup(x => x.Sections).ReturnsEntitySet(new StoreHiveSection[] { section });
            var sectionResult = await service.GetHiveSectionAsync(section.Id);

            sectionResult.Id.Should().Be(section.Id);
        }
Beispiel #12
0
        public async Task GetHiveSectionAsync_EmptyCollection_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.GetHiveSectionAsync(0);
            });
        }
Beispiel #13
0
        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);
        }
Beispiel #14
0
        public async Task GetHiveSectionAsync_PassesHiveSectionId_ThrowsRequestedResourceNotFoundException(
            [Frozen] Mock <IProductStoreHiveContext> contextMock,
            HiveSectionService hiveSectionService,
            IFixture fixture,
            int hiveSectionId)
        {
            var storeHiveSections = fixture.CreateMany <StoreHiveSection>(0).ToArray();

            contextMock.Setup(c => c.Sections).ReturnsEntitySet(storeHiveSections);

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(
                () => hiveSectionService.GetHiveSectionAsync(hiveSectionId));
        }
        public async Task GetHiveSectionAsync_SetWithFiveElements_NotExistedIdAsParametr_ThrowException()
        {
            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.GetHiveSectionAsync(hiveSectionId));
        }
Beispiel #16
0
        public async Task GetHiveSection_Found_Entity_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveSectionService hiveSectionService)
        {
            var listSectionEntity = fixture.CreateMany <StoreHiveSection>(13).ToList();

            context.Setup(c => c.Sections).ReturnsEntitySet(listSectionEntity);

            var hives = await hiveSectionService.GetHiveSectionAsync(listSectionEntity[0].Id);

            Assert.Equal(listSectionEntity[0].Id, hives.Id);
            Assert.Equal(listSectionEntity[0].Code, hives.Code);
            Assert.Equal(listSectionEntity[0].Name, hives.Name);
            Assert.Equal(listSectionEntity[0].IsDeleted, hives.IsDeleted);
        }
        public async Task GetHiveSectionAsync_SetWithFiveElements_IdAsParametr_ReturnedOneElement()
        {
            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);
            var hiveSection = await service.GetHiveSectionAsync(hiveSectionId);

            Assert.Equal(hiveSectionId, hiveSection.Id);
        }
        public async Task GetHiveSectionAsync_SectionId_RequestedResourceNotFoundException(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            // arrange
            var dbSections = fixture.CreateMany <StoreHiveSection>(2).ToList();

            var sectionId = dbSections[0].Id + dbSections[1].Id;

            context.Setup(s => s.Sections).ReturnsEntitySet(dbSections);

            // assert
            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.GetHiveSectionAsync(sectionId));
        }
Beispiel #19
0
        public async Task GetHiveSection_RequestWithExistedId_HiveSectionReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service)
        {
            var hiveSection = new StoreHiveSection
            {
                Id = 1
            };

            context.Setup(c => c.Sections).ReturnsAsyncEntitySet(new[] { hiveSection });

            var resultHive = await service.GetHiveSectionAsync(1);

            Assert.True(hiveSection.Id == resultHive.Id);
        }
Beispiel #20
0
        public async Task UpdateHiveSection_UpdateSuccessfuly_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveSectionService hiveSectionService)
        {
            var listEntity = fixture.CreateMany <StoreHiveSection>(13).ToList();

            listEntity[0].Name = "tests";
            listEntity[0].Code = "tests";
            context.Setup(x => x.Sections).ReturnsEntitySet(listEntity);
            var createRequest = fixture.Create <UpdateHiveSectionRequest>();
            var addedHive     = await hiveSectionService.UpdeteHiveSectionAsync(listEntity[0].Id, createRequest);

            var hiveSection = await hiveSectionService.GetHiveSectionAsync(addedHive.Id);

            Assert.Equal(hiveSection.Id, listEntity[0].Id);
            Assert.Equal(hiveSection.Name, createRequest.Name);
            Assert.Equal(hiveSection.Code, createRequest.Code);
        }
        public async Task GetHiveSection_NoSuchSectionTest(int hiveSectionId)
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

            context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    Id = 1
                }
            });
            var service = new HiveSectionService(context.Object, userContext.Object);

            Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => await service.GetHiveSectionAsync(hiveSectionId));
        }
Beispiel #22
0
        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 UpdateHiveSection_CreateFiveElement_UpdateOneElement(
            [Frozen] Mock <IProductStoreHiveContext> contex,
            HiveSectionService service,
            IFixture fixture)
        {
            var hiveSection = fixture.CreateMany <StoreHiveSection>(5).ToList();
            var hive        = fixture.CreateMany <StoreHive>(3).ToArray();

            contex.Setup(x => x.Sections).ReturnsEntitySet(hiveSection);
            contex.Setup(x => x.Hives).ReturnsEntitySet(hive);
            var hiveSectionUpdate = fixture.Create <UpdateHiveSectionRequest>();
            await service.UpdateHiveSectionAsync(hiveSection[0].Id, hiveSectionUpdate);

            var result = await service.GetHiveSectionAsync(hiveSection[0].Id);

            result.Name.Should().Be(hiveSectionUpdate.Name);
        }
Beispiel #24
0
        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 GetHiveSection_SuccessfulTest(int hiveSectionId)
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

            context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    Id = 1
                }
            });
            var service = new HiveSectionService(context.Object, userContext.Object);

            var section = await service.GetHiveSectionAsync(hiveSectionId);

            Assert.NotNull(section);
        }
Beispiel #26
0
        public async Task GetHiveSectionAsync_PassesCorrectHiveSectionId_ExpectsSuccessfullEqualityAssertion(
            [Frozen] Mock <IProductStoreHiveContext> contextMock,
            HiveSectionService hiveSectionService,
            IFixture fixture)
        {
            var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToArray();

            contextMock.Setup(c => c.Sections).ReturnsEntitySet(storeHiveSections);

            var expectedHiveSection = storeHiveSections[1];
            var actualHiveSection   = await hiveSectionService.GetHiveSectionAsync(storeHiveSections[1].Id);

            Assert.Equal(expectedHiveSection.Id, actualHiveSection.Id);
            Assert.Equal(expectedHiveSection.Name, actualHiveSection.Name);
            Assert.Equal(expectedHiveSection.StoreHiveId, actualHiveSection.HiveId);
            Assert.Equal(expectedHiveSection.Code, actualHiveSection.Code);
            Assert.Equal(expectedHiveSection.IsDeleted, actualHiveSection.IsDeleted);
        }
        public async Task GetHiveSectionAsync_SectionId_Hive(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            // arrange
            var dbSections = fixture.CreateMany <StoreHiveSection>(5).ToList();

            var sectionId = dbSections[3].Id;

            context.Setup(s => s.Sections).ReturnsEntitySet(dbSections);

            // act
            var section = await service.GetHiveSectionAsync(sectionId);

            // assert
            Assert.Equal(dbSections[3].Id, section.Id);
        }
        public async Task DeleteHiveSectionAsync_HiveSectionId_Success(
            [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 = true;

            context.Setup(s => s.Sections).ReturnsEntitySet(dbHiveSections);

            await service.DeleteHiveSectionAsync(hiveSectionId);

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(
                () => service.GetHiveSectionAsync(hiveSectionId));
        }
        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 GetHiveSectionAsync_IdNotPresent_RequestedResourceNotFoundExceptionThrown()
        {
            var mockUserContext = new Mock <IUserContext>();
            var mockHiveContext = new Mock <IProductStoreHiveContext>();
            List <StoreHiveSection> hiveSectionsList = new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    Id = 1
                },
                new StoreHiveSection()
                {
                    Id = 2
                }
            };

            mockHiveContext.Setup(c => c.Sections).ReturnsEntitySet(hiveSectionsList);
            var service = new HiveSectionService(mockHiveContext.Object, mockUserContext.Object);

            Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.GetHiveSectionAsync(0));
        }