コード例 #1
0
        public void Get_WhenFavouritesExistsForAGivenUser_ShouldReturnAllFavourites()
        {
            const int peopleId   = 1;
            var       favourites = new List <Favourite>
            {
                new Favourite {
                    ImageId = 1, Id = 1, PeopleId = peopleId
                },
                new Favourite {
                    ImageId = 2, Id = 2, PeopleId = peopleId
                },
                new Favourite {
                    ImageId = 3, Id = 3, PeopleId = peopleId
                },
                new Favourite {
                    ImageId = 4, Id = 4, PeopleId = 2
                },
            };

            _mockFavouritesBuilder.Setup(x => x.Build(It.IsAny <People>()))
            .Returns(favourites.Where(x => x.PeopleId == peopleId).ToList());

            //Act
            var result = (OkObjectResult)_favouritesController.Get(1);

            //Assert
            var actualFavourites = (List <Favourite>)result.Value;

            Assert.Equal((int)HttpStatusCode.OK, result.StatusCode);
            Assert.Equal(3, actualFavourites.Count);
            Assert.Equal(favourites[0].ImageId, actualFavourites[0].ImageId);
            Assert.Equal(favourites[1].ImageId, actualFavourites[1].ImageId);
            Assert.Equal(favourites[2].ImageId, actualFavourites[2].ImageId);
        }
コード例 #2
0
        public async Task GetFavourites_test()
        {
            var customerID = Guid.NewGuid();
            var customer   = new CustomerPoco()
            {
                CustomerId = customerID
            };

            // Arrange
            var mockFavouriteskService = new Mock <IFavouritesService>();

            mockFavouriteskService.Setup(x => x.GetFavouriteDrugs(customerID))
            .Returns(Task.FromResult <IEnumerable <DrugPoco> >(new List <DrugPoco> {
                new DrugPoco()
                {
                    DrugName = "drug1"
                },
                new DrugPoco()
                {
                    DrugName = "drug2"
                }
            }));

            var mockCustomersService = new Mock <ICustomersService>();

            mockCustomersService.Setup(x => x.GetCustomer(customerID))
            .Returns(Task.FromResult(customer));

            // Arrange
            var controller = new FavouritesController(mockFavouriteskService.Object, mockCustomersService.Object);

            // Act
            var favourites = await controller.Get();

            // Assert
            Assert.NotNull(favourites);
            //Assert.Equal(2, favourites.Count());
        }