Пример #1
0
        public void NewTestWhenNewProfileIsCreated()
        {
            DoctorProfile dr            = new DoctorProfile();
            var           dbContextMock = new Mock <ApplicationDbContext>();
            var           dbSetMock     = new Mock <DbSet <DoctorProfile> >();

            dbSetMock.Setup(m => m.Add(dr));
            dbContextMock.Setup(m => m.DoctorsProfiles).Returns(dbSetMock.Object);
            dbContextMock.Setup(m => m.DoctorsProfiles.Add(dr));
            DoctorProfileController controller = new DoctorProfileController(dbContextMock.Object);

            controller.New(dr);
            dbContextMock.Verify(m => m.DoctorsProfiles.Add(dr), Times.Once());
        }
Пример #2
0
        public void NewTestWhenReturnView()
        {
            var fakeIdentity    = new GenericIdentity("User");
            var principal       = new GenericPrincipal(fakeIdentity, null);
            var fakeHttpContext = new Mock <HttpContextBase>();

            fakeHttpContext.Setup(t => t.User).Returns(principal);
            var controllerContext = new Mock <ControllerContext>();

            controllerContext.Setup(t => t.HttpContext).Returns(fakeHttpContext.Object);
            DoctorProfileController controller = new DoctorProfileController();

            controller.ControllerContext = controllerContext.Object;
            var result = controller.New() as ViewResult;

            Assert.IsInstanceOfType(result.Model, typeof(DoctorProfile));
        }