Exemplo n.º 1
0
        public async Task Update(KindService kindService)
        {
            var kindServicesFromDb = GetById(kindService.Id);

            kindServicesFromDb.Name = kindService.Name;
            await _context.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public void GetById_ValidId_KindElement()
        {
            int validId = 1;
            var kind    = new Kind
            {
                KindId = 1,
                Type   = "Product"
            };

            var mockKindRepository = new Mock <IRepository <Kind> >();

            mockKindRepository.Setup(repo => repo.GetById(It.IsAny <int>()))
            .Returns((int id) =>
            {
                if (id == validId)
                {
                    return(new SuccessResult <Kind>(kind));
                }
                return(new NoneResult <Kind>());
            });

            var kindService = new KindService(mockKindRepository.Object);

            var resultKind = kindService.GetById(validId).GetSuccessResult();

            Assert.AreNotEqual(resultKind, null);
            Assert.AreEqual(resultKind.KindId, validId);
            Assert.AreEqual(resultKind.Type, kind.Type);
            mockKindRepository.Verify(mock => mock.GetById(validId), Times.Once());
        }
Exemplo n.º 3
0
        public void GetAll_KindsCollection()
        {
            var kinds = new List <Kind>
            {
                new Kind
                {
                    KindId = 1,
                    Type   = "MyType-1"
                },
                new Kind
                {
                    KindId = 2,
                    Type   = "MyType-2"
                }
            };

            var mockKindRepository = new Mock <IRepository <Kind> >();

            mockKindRepository.Setup(repo => repo.GetAll())
            .Returns(new SuccessResult <IReadOnlyCollection <Kind> >(kinds));

            var kindProvider = new KindService(mockKindRepository.Object);

            var resultKinds = kindProvider.GetAll().GetSuccessResult();

            Assert.AreNotEqual(resultKinds, null);
            Assert.AreEqual(kinds.Count, resultKinds.Count);
            mockKindRepository.Verify(mock => mock.GetAll(), Times.Once());
        }
Exemplo n.º 4
0
        public async Task GetKind_should_thrown_exception_with_null_id()
        {
            //Arrange
            KindService sut = new KindService(KindRepo, VideoRepo, Mapper);

            //Act, Assert
            await Assert.ThrowsAsync <ArgumentNullException>(() => sut.GetKindAsync(null));
        }
Exemplo n.º 5
0
        public async Task GetKind_should_return_all_Kinds()
        {
            //Arrange
            KindService sut = new KindService(KindRepo, VideoRepo, Mapper);

            //Act
            IEnumerable <KindResponse> result = await sut.GetKindAsync();

            //Assert
            result.Should().HaveCountGreaterOrEqualTo(2);
            Assert.NotNull(result.First().Name);
        }
Exemplo n.º 6
0
        public void Delete_InvalidId_Throws()
        {
            int invalidId          = 0;
            var mockKindRepository = new Mock <IRepository <Kind> >();

            mockKindRepository.Setup(repo => repo.Delete(It.IsAny <int>()));

            var kindProvider = new KindService(mockKindRepository.Object);

            kindProvider.Delete(invalidId);

            mockKindRepository.Verify(mock => mock.Delete(invalidId), Times.Once());
        }
Exemplo n.º 7
0
        public void Save_Null_Throws()
        {
            Kind invalidObj         = null;
            var  mockKindRepository = new Mock <IRepository <Kind> >();

            mockKindRepository.Setup(repo => repo.Save(It.IsAny <Kind>()));

            var kindProvider = new KindService(mockKindRepository.Object);

            kindProvider.Save(invalidObj);

            mockKindRepository.Verify(mock => mock.Save(invalidObj), Times.Once());
        }
Exemplo n.º 8
0
        public void GetById_InvalidId_Throws()
        {
            int invalidId = 0;

            var mockKindRepository = new Mock <IRepository <Kind> >();

            mockKindRepository.Setup(repo => repo.GetById(It.IsAny <int>()));

            var kindService = new KindService(mockKindRepository.Object);

            var resultKind = kindService.GetById(invalidId);

            mockKindRepository.Verify(mock => mock.GetById(invalidId), Times.Once());
        }
Exemplo n.º 9
0
        public async Task GetKind_should_return_kind_with_specified_id(string guid)
        {
            //Arrange
            KindService sut = new KindService(KindRepo, VideoRepo, Mapper);

            //Act
            KindResponse result = await sut.GetKindAsync(new GetKindRequest()
            {
                Id = new Guid(guid)
            });

            //Assert
            result.KindId.Should().Be(new Guid(guid));
            Assert.NotNull(result.Name);
        }
Exemplo n.º 10
0
        public async Task GetVideosByKindId_should_return_specified_videos(string guid)
        {
            //Arrange
            KindService sut = new KindService(KindRepo, VideoRepo, Mapper);

            //Act
            IEnumerable <VideoResponse> result = await sut.GetVideosByKindIdAsync(new GetKindRequest()
            {
                Id = new Guid(guid)
            });

            //Assert
            Assert.Equal(2, result.Count());
            Assert.NotNull(result.First().AltTitle);
        }
Exemplo n.º 11
0
        public void Setup()
        {
            SetUpContextOptions();

            SetUpJwtOptions();

            SetUpServices();

            SetUpMapper();

            SetUpLogger();

            SetUpContext();

            KindService = new KindService(Context, Mapper, Logger);
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Update([FromBody] KindService kindService)
        {
            try
            {
                if (kindService == null)
                {
                    return(BadRequest());
                }

                await _kindService.Update(kindService);

                return(Ok(kindService));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e));
            }
        }
Exemplo n.º 13
0
        public async Task AddKind_should_return_the_expected_kind()
        {
            //Arrange
            AddKindRequest expectedKind = new AddKindRequest()
            {
                KindName = GenData.Create <string>()
            };

            KindService sut = new KindService(KindRepo, VideoRepo, Mapper);

            //Act
            KindResponse result = await sut.AddKindAsync(expectedKind);

            //Assert
            //expectedKind.Should().BeEquivalentTo(result, o =>
            //    o.Excluding(x => x.KindId));
            Assert.Equal(expectedKind.KindName, result.Name);
        }
Exemplo n.º 14
0
        public void Save_ValidKindObj_ObjSaved()
        {
            var kinds = new List <Kind>();
            var kind  = new Kind
            {
                KindId = 1,
                Type   = "Product"
            };

            var mockKindRepository = new Mock <IRepository <Kind> >();

            mockKindRepository.Setup(repo => repo.Save(It.IsAny <Kind>()))
            .Callback((Kind value) => kinds.Add(value));

            var kindService = new KindService(mockKindRepository.Object);

            kindService.Save(kind);

            Assert.AreEqual(kinds.Count, 1);
            Assert.IsTrue(kinds.Contains(kind));
            mockKindRepository.Verify(mock => mock.Save(kind), Times.Once());
        }
Exemplo n.º 15
0
        public void Delete_ValidId_ObjDeleted()
        {
            int validId = 1;
            var kinds   = new List <Kind>
            {
                new Kind
                {
                    KindId = 1,
                    Type   = "Product"
                },
                new Kind
                {
                    KindId = 2,
                    Type   = "MyType-2"
                }
            };
            int countBeforeDelete = kinds.Count;

            var mockKindRepository = new Mock <IRepository <Kind> >();

            mockKindRepository.Setup(repo => repo.Delete(It.IsAny <int>()))
            .Callback((int id) =>
            {
                if (id == validId)
                {
                    kinds.RemoveAll(kind => kind.KindId == id);
                }
            });

            var kindProvider = new KindService(mockKindRepository.Object);

            kindProvider.Delete(validId);

            Assert.AreEqual(kinds.Count, countBeforeDelete - 1);
            Assert.IsFalse(kinds.Exists(kind => kind.KindId == validId));
            mockKindRepository.Verify(mock => mock.Delete(validId), Times.Once());
        }
Exemplo n.º 16
0
 public async Task Add(KindService kindService)
 {
     _context.kindServices.Add(kindService);
     await _context.SaveChangesAsync();
 }