Exemple #1
0
        public void AttendanceThrowException_WhenUserNull()
        {
            // Arrange
            var identity = new IdentityUser()
            {
                Id = "1"
            };
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, identity.Id),
            }, "mock"));

            var mockUserManager = new Mock <IUserService>();

            mockUserManager.Setup(x => x.GetApplicationUser(user)).Returns(Task.FromResult(new ApplicationUser()));
            var mockLogic = new Mock <IPersonalCabinetLogic>();

            var controller = new PersonalCabinetController(mockUserManager.Object, mockLogic.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user
                }
            };

            // Assert
            Assert.ThrowsAsync <Exception>(() => controller.Attendance());
        }
Exemple #2
0
        public async Task ReturnsCorrectData_AttendanceAsync()
        {
            // Arrange
            var identity = new IdentityUser()
            {
                Id = "1"
            };
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, identity.Id),
            }, "mock"));

            var mockUserManager = new Mock <IUserService>();

            mockUserManager.Setup(x => x.GetApplicationUser(user)).Returns(Task.FromResult(new ApplicationUser()
            {
                Id = "1"
            }));
            var mockLogic = new Mock <IPersonalCabinetLogic>();
            var atees     = new List <Attendance>()
            {
                new Attendance
                {
                    Id          = 1,
                    PassesCount = 3,
                    Subject     = new Subject {
                        Name = "Math", LecturesCount = 5
                    }
                }
            };
            var stud = new Student()
            {
                Id = 1
            };

            mockLogic.Setup(logic => logic.GetAttendanceById(1)).Returns(Task.FromResult(atees));
            mockLogic.Setup(logic => logic.GetStudentById("1")).Returns(Task.FromResult(stud));


            var controller = new PersonalCabinetController(mockUserManager.Object, mockLogic.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user
                }
            };
            //  Act
            var res = await controller.Attendance();

            // Assert
            var viewResult = Assert.IsType <ViewResult>(res);

            var model = Assert.IsAssignableFrom <List <AttendanceViewModel> >(
                viewResult.ViewData.Model);

            Assert.Equal(model[0].Subject, atees[0].Subject.Name);
            Assert.Equal(model[0].LecturesCount, atees[0].Subject.LecturesCount);
            Assert.Equal(model[0].PassesCount, atees[0].PassesCount);
        }