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); }
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)); }
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); }
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)); }