Beispiel #1
0
        public void PostReturnsMultipleObjects() //vraca kolekciju objekata
        {
            // Arrange
            List <Hotel> employee = new List <Hotel>();

            employee.Add(new Hotel {
                Id = 4, Naziv = "Novica Cankovic"
            });
            employee.Add(new Hotel {
                Id = 5, Naziv = "Snezana Gardinovacki"
            });

            var mockRepository = new Mock <IHotelRepository>();

            mockRepository.Setup(x => x.GetAll()).Returns(employee.AsEnumerable());
            var controller = new HoteliController(mockRepository.Object);

            // Act
            IEnumerable <Hotel> result = controller.Get();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(employee.Count, result.ToList().Count);
            Assert.AreEqual(employee.ElementAt(0), result.ElementAt(0));
            Assert.AreEqual(employee.ElementAt(1), result.ElementAt(1));
        }
Beispiel #2
0
        public void GetReturnsEmployeesWithSameId() //200(OK) i objekat
        {
            // Arange
            var mockRepository = new Mock <IHotelRepository>();

            mockRepository.Setup(x => x.GetById(1)).Returns(new Hotel {
                Id = 1
            });

            var controller = new HoteliController(mockRepository.Object);

            // Act
            IHttpActionResult actionResult = controller.Get(1);
            var contentResult = actionResult as OkNegotiatedContentResult <Hotel>;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(1, contentResult.Content.Id);
        }