コード例 #1
0
        public void GetDiscountTest()
        {
            // Arrange
            var      configuration = LocalConfiguration.GetConfiguration();
            var      repository    = new Mock <IDiscountRepository>();
            Discount discount      = new Discount()
            {
                DiscountPer = 10
            };

            repository.Setup(x => x.GetDiscountByUserRole(It.IsAny <Guid>())).Returns(discount);

            //Act
            var target = new DiscountService(repository.Object);
            var result = target.GetDiscountByUserRole(Guid.NewGuid());

            // Assert
            Assert.Equal(10, result);
        }
コード例 #2
0
        public void Get_Forbidden_When_User_Not_Active()
        {
            // Arrange
            var configuration = LocalConfiguration.GetConfiguration();
            var repository    = new Mock <IUserRepository>();

            User user = null;

            repository.Setup(x => x.GetUser(It.IsAny <string>())).Returns(user);

            //Act
            AuthRequestDto authRequest = new AuthRequestDto
            {
                Password = "******",
                UserName = "******"
            };
            var target = new UserService(repository.Object, configuration);

            // Assert
            Assert.Throws <UnauthorizedAccessException>(() => target.AuthenticateUser(authRequest));
        }
コード例 #3
0
        public void GetUserTest()
        {
            // Arrange
            var      configuration = LocalConfiguration.GetConfiguration();
            var      repository    = new Mock <IUserRepository>();
            UserRole userRole      = new UserRole
            {
                Id        = Guid.NewGuid(),
                Name      = "Privileged",
                IsActive  = true,
                CreatedOn = DateTime.Now
            };

            User user = new User
            {
                CreatedOn  = DateTime.Now,
                Id         = Guid.NewGuid(),
                IsActive   = true,
                Name       = "Mathew",
                Password   = "******",
                UserRole   = userRole,
                UserRoleId = userRole.Id
            };

            repository.Setup(x => x.GetUser(It.IsAny <string>())).Returns(user);

            //Act
            AuthRequestDto authRequest = new AuthRequestDto
            {
                Password = "******",
                UserName = "******"
            };
            var target = new UserService(repository.Object, configuration);
            var result = target.AuthenticateUser(authRequest);

            // Assert
            Assert.NotNull(result);
            Assert.Equal("Mathew", result.UserName);
            Assert.Equal("Privileged", result.UserRole);
        }
コード例 #4
0
        public void Get_Forbidden_When_User_Password_Not_Same()
        {
            // Arrange
            var configuration = LocalConfiguration.GetConfiguration();
            var repository    = new Mock <IUserRepository>();

            UserRole userRole = new UserRole
            {
                Id        = Guid.NewGuid(),
                Name      = "Privileged",
                IsActive  = true,
                CreatedOn = DateTime.Now
            };

            User user = new User
            {
                CreatedOn  = DateTime.Now,
                Id         = Guid.NewGuid(),
                IsActive   = false,
                Name       = "Mathew",
                Password   = "******",
                UserRole   = userRole,
                UserRoleId = userRole.Id
            };

            repository.Setup(x => x.GetUser(It.IsAny <string>())).Returns(user);

            //Act
            AuthRequestDto authRequest = new AuthRequestDto
            {
                Password = "******",
                UserName = "******"
            };
            var target = new UserService(repository.Object, configuration);

            // Assert
            Assert.Throws <UnauthorizedAccessException>(() => target.AuthenticateUser(authRequest));
        }