public async Task CreateHiveSectionAsync_UniqueCode_HiveSectionWithSpecifiedCodeCreated()
        {
            const string newCode        = "cc";
            var          newHiveSection = new UpdateHiveSectionRequest()
            {
                Code = newCode
            };
            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);

            var hive = await service.CreateHiveSectionAsync(1, newHiveSection);

            Assert.Equal(newCode, hive.Code);
        }
Exemplo n.º 2
0
        public async Task CreateHiveSectionAsync_CreateSectionWithExistingSectionCode_ExceptionThrown()
        {
            var sections = new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    Id = 0, Code = "CODE1"
                },
                new StoreHiveSection()
                {
                    Id = 1, Code = "CODE2"
                }
            };
            var context = new Mock <IProductStoreHiveContext>();

            context.Setup(c => c.Sections).ReturnsEntitySet(sections);
            var service = new HiveSectionService(context.Object, new UserContext());
            var request = new UpdateHiveSectionRequest {
                Code = "CODE1"
            };

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() =>
            {
                await service.CreateHiveSectionAsync(request);
            });
        }
        public async Task CreateHiveSectionAsync_SuccessfulTest(int hiveId, string name, string code)
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

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

            await service.CreateHiveSectionAsync(hiveId, request);

            var sections = await service.GetHiveSectionsAsync(hiveId);

            Assert.Single(sections);
        }
        public async Task CreateHiveSectionAsync_CodeAlreadyPresent_RequestedResourceHasConflictExceptionThrown()
        {
            var newHiveSection = new UpdateHiveSectionRequest()
            {
                Code = "aa"
            };
            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 <RequestedResourceHasConflictException>(() => service.CreateHiveSectionAsync(1, newHiveSection));
        }
Exemplo n.º 5
0
        public async void CreateHiveSectionAsync_EntityWithExistedCode_CustomExceptionThrows([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture)
        {
            Configure(context, fixture);
            var updateHiveSectionRequest = fixture.Create <UpdateHiveSectionRequest>();

            updateHiveSectionRequest.Code = _section[0].Code;

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => service.CreateHiveSectionAsync(updateHiveSectionRequest));
        }
Exemplo n.º 6
0
        public async void CreateHiveSectionAsync_ValidEntity_SuccessfullHiveAddition([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture)
        {
            Configure(context, fixture);
            var updateHiveSectionRequest = fixture.Create <UpdateHiveSectionRequest>();

            var result = await service.CreateHiveSectionAsync(updateHiveSectionRequest);

            result.Code.Should().Be(updateHiveSectionRequest.Code);
            result.Name.Should().Be(updateHiveSectionRequest.Name);
        }
Exemplo n.º 7
0
        public async Task CreateHiveSectionAsync_EmptyCollection_NewSectionReturned()
        {
            var context = new Mock <IProductStoreHiveContext>();

            context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>());
            var service = new HiveSectionService(context.Object, new UserContext());
            var request = new UpdateHiveSectionRequest {
                Code = "CODE1", Name = "Section"
            };

            var section = await service.CreateHiveSectionAsync(request);

            Assert.Equal(request.Code, section.Code);
            Assert.Equal(request.Name, section.Name);
        }
        public async Task CreateHiveSectio_SetOneElement_OneReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            var hives = fixture.CreateMany <StoreHive>(3).ToArray();

            context.Setup(x => x.Hives).ReturnsEntitySet(hives);
            context.Setup(x => x.Sections).ReturnsEntitySet(new List <StoreHiveSection>());
            var section = fixture.Create <UpdateHiveSectionRequest>();
            await service.CreateHiveSectionAsync(section, hives[0].Id);

            var result = await service.GetHiveSectionsAsync();

            result.Count.Should().Be(1);
        }
        public async Task CreateHiveSectio_RequestedResourceNotFoundException(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            var hives = fixture.CreateMany <StoreHive>(3).ToArray();

            context.Setup(x => x.Hives).ReturnsEntitySet(hives);
            var sections = fixture.CreateMany <StoreHiveSection>(3).ToList();

            context.Setup(x => x.Sections).ReturnsEntitySet(sections);
            var         section = fixture.Create <UpdateHiveSectionRequest>();
            Func <Task> act     = async() => await service.CreateHiveSectionAsync(section, 20);

            act.Should().Throw <RequestedResourceNotFoundException>();
        }
Exemplo n.º 10
0
        public async Task CreateHiveSection_AddedSuccessfuly_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveSectionService hiveSectionService)
        {
            var listEntity     = fixture.CreateMany <StoreHiveSection>(13).ToList();
            var listHiveEntity = fixture.CreateMany <StoreHive>(13).ToList();

            context.Setup(x => x.Hives).ReturnsEntitySet(listHiveEntity);
            context.Setup(x => x.Sections).ReturnsEntitySet(listEntity);
            var createRequest = fixture.Create <UpdateHiveSectionRequest>();

            createRequest.StoreHiveId = listHiveEntity[0].Id;
            var addedHiveSection = await hiveSectionService.CreateHiveSectionAsync(createRequest);

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

            Assert.Equal(hiveSection.Name, createRequest.Name);
            Assert.Equal(hiveSection.Code, createRequest.Code);
        }
Exemplo n.º 11
0
        public async Task CreateHiveSectionAsync_PassesUpdateHiveSectionRequest_ThrowsRequestedResourceNotFoundException(
            [Frozen] Mock <IProductStoreHiveContext> contextMock,
            HiveSectionService hiveSectionService,
            IFixture fixture)
        {
            var storeHives        = fixture.CreateMany <StoreHive>(3).ToList();
            var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToList();

            contextMock.Setup(c => c.Hives).ReturnsEntitySet(storeHives);
            contextMock.Setup(c => c.Sections).ReturnsEntitySet(storeHiveSections);
            var createRequest = new UpdateHiveSectionRequest {
                Code = "12345", Name = "qwerty", HiveId = 123
            };

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(
                () => hiveSectionService.CreateHiveSectionAsync(createRequest));
        }
        public async Task CreateHiveSectionAsync_HiveIdAndUpdateRequest_RequestedResourceHasConflictException(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            var dbUpdateRequest = fixture.Create <UpdateHiveSectionRequest>();

            var dbHiveSections = fixture.CreateMany <StoreHiveSection>(1).ToList();

            dbHiveSections[0].Code = dbUpdateRequest.Code;

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

            var hiveId = 1;

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(
                () => service.CreateHiveSectionAsync(hiveId, dbUpdateRequest));
        }
        public async Task CreateHiveSectionAsync_CreateRequestAsParametr_NotExistedHiveId_ThrowException()
        {
            var createReq = new UpdateHiveSectionRequest()
            {
                Name   = "CreateName",
                Code   = "TEST7",
                HiveId = 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.CreateHiveSectionAsync(createReq));
        }
Exemplo n.º 14
0
        public async Task CreateHiveSection_TryCreateHiveSection_HiveSectionEntityReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service)
        {
            var hiveSection = new UpdateHiveSectionRequest
            {
                Code = "Code",
                Name = "Name"
            };

            context.Setup(c => c.Sections).ReturnsAsyncEntitySet(new StoreHiveSection[0]);

            var createdHiveSection = await service.CreateHiveSectionAsync(hiveSection);

            Assert.True(
                createdHiveSection.Name == hiveSection.Name &&
                createdHiveSection.Code == hiveSection.Code &&
                createdHiveSection.IsDeleted == false);
        }
Exemplo n.º 15
0
        public async Task CreateHiveSection_TryCreateHiveSection_ElementWasAddedToContext(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service)
        {
            var hiveSection = new UpdateHiveSectionRequest
            {
                Code = "Code",
                Name = "Name"
            };

            context.Setup(c => c.Sections).ReturnsAsyncEntitySet(new StoreHiveSection[0]);

            await service.CreateHiveSectionAsync(hiveSection);

            Assert.True(context.Object.Sections.Count() == 1);
            Assert.Contains(context.Object.Sections, h => h.Code == hiveSection.Code &&
                            h.Name == hiveSection.Name &&
                            h.IsDeleted == false);
        }
        public async Task CreateHiveSectionAsync_CreateRequestAsParametr_ReturnedCreatedElement()
        {
            var createReq = new UpdateHiveSectionRequest()
            {
                Name   = "CreateName",
                Code   = "TEST1",
                HiveId = 2
            };

            var storeContext = new Mock <IProductStoreHiveContext>();
            var userContext  = new Mock <IUserContext>();

            storeContext.Setup(c => c.Hives).ReturnsAsyncEntitySet(_hives);
            storeContext.Setup(c => c.Sections).ReturnsAsyncEntitySet(new StoreHiveSection[0]);

            var service     = new HiveSectionService(storeContext.Object, userContext.Object);
            var hiveSection = await service.CreateHiveSectionAsync(createReq);

            Assert.Equal(createReq.Name, hiveSection.Name);
            Assert.Equal(createReq.Code, hiveSection.Code);
            Assert.Equal(createReq.HiveId, hiveSection.HiveId);
        }
Exemplo n.º 17
0
        public async Task CreateHiveSectionAsync_PassesUpdateHiveSectionRequest_ExpectsSuccessfullEqualityAssertion(
            [Frozen] Mock <IProductStoreHiveContext> contextMock,
            HiveSectionService hiveSectionService,
            IFixture fixture)
        {
            var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToList();
            var storeHives        = fixture.CreateMany <StoreHive>(3).ToList();

            contextMock.Setup(x => x.Hives).ReturnsEntitySet(storeHives);
            contextMock.Setup(x => x.Sections).ReturnsEntitySet(storeHiveSections);
            var createRequest = new UpdateHiveSectionRequest {
                Name = "qwerty", Code = "12345", HiveId = storeHives[0].Id
            };

            var expectedHiveSection = await hiveSectionService.CreateHiveSectionAsync(createRequest);

            var actualHiveSection = await hiveSectionService.GetHiveSectionAsync(expectedHiveSection.Id);

            Assert.Equal(expectedHiveSection.Name, actualHiveSection.Name);
            Assert.Equal(expectedHiveSection.Code, actualHiveSection.Code);
            Assert.Equal(expectedHiveSection.HiveId, actualHiveSection.HiveId);
        }
Exemplo n.º 18
0
        public async void CreateHiveSectionSuccesFull()
        {
            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);

            var createRequest = new UpdateHiveSectionRequest()
            {
                Name = "newHive",
                Id   = 1,
                Code = "111341"
            };
            await service.CreateHiveSectionAsync(createRequest);

            Assert.NotNull(service.GetHiveSectionsAsync());
        }
        public async Task CreateHiveSectionAsync_UpdateRequest_Success(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            var dbHiveSections = fixture.CreateMany <StoreHiveSection>(0).ToList();

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

            var dbHives = fixture.CreateMany <StoreHive>(1).ToList();

            var hiveId = 1;

            dbHives[0].Id = hiveId;

            context.Setup(s => s.Hives).ReturnsEntitySet(dbHives);

            var dbUpdateRequest = fixture.Create <UpdateHiveSectionRequest>();

            var createdHiveSection = await service.CreateHiveSectionAsync(hiveId, dbUpdateRequest);

            Assert.Equal(dbUpdateRequest.Name, createdHiveSection.Name);
            Assert.Equal(dbUpdateRequest.Code, createdHiveSection.Code);
        }
Exemplo n.º 20
0
        public async Task CreateHiveSection_CreateHiveSectionWithExistedCode_ExceptionThrown(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service)
        {
            var hiveSection = new StoreHiveSection
            {
                Id   = 1,
                Code = "Code"
            };

            var newHiveSection = new UpdateHiveSectionRequest
            {
                Code = hiveSection.Code
            };

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

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() => await service.CreateHiveSectionAsync(newHiveSection));
        }
Exemplo n.º 21
0
        public async Task CreateHiveSection_ConflictException_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveSectionService hiveSectionService, string code)
        {
            var listEntity = fixture.CreateMany <StoreHiveSection>(13).ToList();

            listEntity[0].Code = code;
            var listHiveEntity = fixture.CreateMany <StoreHive>(0).ToList();
            var createRequest  = fixture.Create <UpdateHiveSectionRequest>();

            createRequest.Code = code;
            context.Setup(x => x.Sections).ReturnsEntitySet(listEntity);
            context.Setup(x => x.Hives).ReturnsEntitySet(listHiveEntity);
            var ex = await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => hiveSectionService.CreateHiveSectionAsync(createRequest));

            Assert.Equal(typeof(RequestedResourceHasConflictException), ex.GetType());
        }
        public void CreateHiveSectionAsync_SuchHiveSectionAlreadyExistsTest(int hiveId, 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()
                {
                    Code = "11111"
                }
            });
            var service = new HiveSectionService(context.Object, userContext.Object);
            var request = new UpdateHiveSectionRequest
            {
                Name = name,
                Code = code,
            };

            Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() => await service.CreateHiveSectionAsync(hiveId, request));
        }