Пример #1
0
        public void TestZadatakServiceFindByIdInvalid()
        {
            var service = new ZadatakService(unitOfWork.Object);
            var result  = service.FindById(null);

            Assert.Null(result);
        }
Пример #2
0
        public void TestZadatakServiceFindById()
        {
            var service       = new ZadatakService(unitOfWork.Object);
            var result        = service.FindById(2);
            var zadatakResult = Assert.IsType <Zadatak>(result);
            var expected      = unitOfWork.Object.ZadatakRepository.FindById(2);

            Assert.Equal(expected, zadatakResult);
        }
Пример #3
0
        public void TestZadatakServiceInsertZadatak()
        {
            //Arrange
            var newZadatak = new Zadatak()
            {
                Id           = 3,
                Datum        = new DateTime(2020, 04, 29),
                Status       = Enumerations.Status.Kreiran.ToString(),
                Teren        = "Niš",
                NazivZadatka = "Kontrola policijskog časa"
            };

            newZadatak.Angazovanja = new List <Angazovanje>()
            {
                new Angazovanje()
                {
                    DatumUnosaOcene = null,
                    Ocena           = null,
                    ZadatakId       = 1,
                    Pas             = unitOfWork.Object.PasRepository.FindById(1),
                    PasId           = 1,
                    Zadatak         = newZadatak
                }, new Angazovanje()
                {
                    DatumUnosaOcene = null,
                    Ocena           = null,
                    ZadatakId       = 1,
                    Pas             = unitOfWork.Object.PasRepository.FindById(2),
                    PasId           = 2,
                    Zadatak         = newZadatak
                },
                new Angazovanje()
                {
                    DatumUnosaOcene = null,
                    Ocena           = null,
                    ZadatakId       = 1,
                    Pas             = unitOfWork.Object.PasRepository.FindById(3),
                    PasId           = 3,
                    Zadatak         = newZadatak
                }
            };
            var service = new ZadatakService(unitOfWork.Object);

            //Act
            service.Insert(newZadatak);
            var result = service.GetAll();
            var zadaci = unitOfWork.Object.ZadatakRepository.GetAll();

            Zadatak zadatak = service.FindById(newZadatak.Id);

            //Assert
            Assert.Equal(newZadatak.Id, zadatak.Id);
            Assert.Equal(zadaci.Count(), result.Count());
            unitOfWork.Verify(x => x.Save(), Times.Once);
            unitOfWork.Verify(x => x.ZadatakRepository.Insert(It.Is <Zadatak>(p => p.Id == 3)), Times.Once);
        }