コード例 #1
0
        public async Task VisitsController_Add_Test()
        {
            bool called             = false;
            var  visitRepository    = new Data.Repositories.Fakes.StubIVisitRepository();
            var  employeeRepository = new Data.Repositories.Fakes.StubIEmployeeRepository();

            var visit = new Visit()
            {
                VisitId = 1,
            };

            visitRepository.AddAsyncVisit = (visitParam) =>
            {
                Assert.IsTrue(visitParam.VisitId == visit.VisitId);
                called = true;
                return(Task.FromResult(10));
            };

            visitRepository.GetCompleteInfoAsyncInt32PictureType = (visitId, pictureType) =>
            {
                return(Task.FromResult(new Visit()));
            };

            var target = new VisitsController(visitRepository, new SecurityHelper(), employeeRepository);
            await target.Add(visit);

            Assert.IsTrue(called);
        }
コード例 #2
0
        public async Task VisitsController_Add_Failed_Test()
        {
            var visitRepository    = new Data.Repositories.Fakes.StubIVisitRepository();
            var employeeRepository = new Data.Repositories.Fakes.StubIEmployeeRepository();

            var target = new VisitsController(visitRepository, new SecurityHelper(), employeeRepository);
            await target.Add(null);
        }
コード例 #3
0
            public void CallAddOnce_WhenPostedValidViewModel()
            {
                // Arrange
                var visitsServiceMock         = new Mock <IVisitsService>();
                var municipalitiesServiceMock = new Mock <IMunicipalitiesService>();
                var usersServiceMock          = new Mock <IUserService>();
                var pageServiceMock           = new Mock <IPageService <Visit> >();

                var controller = new VisitsController(visitsServiceMock.Object, municipalitiesServiceMock.Object, usersServiceMock.Object, pageServiceMock.Object);

                var visitDetailsModel = new VisitDetailsViewModel();

                visitsServiceMock.Setup(vs => vs.Add(It.IsAny <Visit>()));

                // Act
                controller.Add(visitDetailsModel);

                // Assert
                visitsServiceMock.Verify(vs => vs.Add(It.IsAny <Visit>()), Times.Once());
            }