コード例 #1
0
        public void Get_WhenCalled_ShouldInvokeAllMedicinesOfRepository( )
        {
            //Arrange
            var repositoryServiceMock = new Mock <IRepository>();
            var sut = new MedicinesController(repositoryServiceMock.Object);

            //Act
            sut.Get();

            //Assert
            repositoryServiceMock.Verify(m => m.AllMedicines, Times.Once);
        }
コード例 #2
0
        public async Task Get_CorrectData_MedicineHeaderViewModelListAsync()
        {
            // Arrange
            var mock       = new Mock <IMedicineStoreRepository>();
            var mockMapper = new Mock <IMapper>();

            mock.Setup(x => x.GetAllMedicinesAsync())
            .Returns(() => Task.FromResult(GetMedicineList()));
            mockMapper.Setup(x => x.Map <IEnumerable <MedicineHeaderViewModel> >(It.IsAny <List <Medicine> >()))
            .Returns(() => GetMedicineHeaderViewModel());

            var controller = new MedicinesController(mock.Object, mockMapper.Object);

            // Act
            var actionResult = await controller.Get() as OkObjectResult;

            var result = actionResult.Value as List <MedicineHeaderViewModel>;

            // Assert
            Assert.Equal((int)HttpStatusCode.OK, actionResult.StatusCode);
            Assert.Equal(2, result.Count);
        }