public void CreateUserAsync_UserForRegistrationDtoValid_ReturnsUserFullDetailsDto() { var mockDal = Substitute.For <IUserDal>(); var mockLogger = Substitute.For <ILogger <UserAdministrationService> >(); var mockCryptoSvc = Substitute.For <ICryptographyService>(); var adminSvc = new UserAdministrationService(mockLogger, mockDal, mockCryptoSvc); var mockRegistration = new UserForRegistrationDto() { Title = Title.Miss, FirstName = "Aoife", LastName = "McGonagle", Username = "******", Password = "******", ConfirmPassword = "******", JobDescription = "Head Honcho", Role = UserRole.MedicalPractitioner, State = AccountState.Active }; var mockJobDescription = new JobDescription() { Description = "Head Honcho", Role = UserRole.MedicalPractitioner }; var mockEmployeeDetails = new Employee() { Firstname = "Aoife", Lastname = "McGonagle", Title = Title.Miss, }; var mockUser = new User() { EmployeeDetails = mockEmployeeDetails, Username = "******", JobDescription = mockJobDescription, State = AccountState.Active }; mockDal.AddAsync(Arg.Any <User>()).Returns(mockUser); var result = adminSvc.CreateUserAsync(mockRegistration).GetAwaiter().GetResult(); Assert.That(result, Is.Not.Null); Assert.That(result.Title, Is.EqualTo(Title.Miss)); Assert.That(result.Firstname, Is.EqualTo("Aoife")); Assert.That(result.Lastname, Is.EqualTo("McGonagle")); Assert.That(result.Username, Is.EqualTo("amcg")); Assert.That(result.JobDescription, Is.EqualTo("Head Honcho")); Assert.That(result.Role, Is.EqualTo(UserRole.MedicalPractitioner)); Assert.That(result.State, Is.EqualTo(AccountState.Active)); }
public void CreateUserAsync_UserForRegistrationDtoNull_ThrowsArgumentNullException() { var mockDal = Substitute.For <IUserDal>(); var mockLogger = Substitute.For <ILogger <UserAdministrationService> >(); var mockCryptoSvc = Substitute.For <ICryptographyService>(); var adminSvc = new UserAdministrationService(mockLogger, mockDal, mockCryptoSvc); var e = Assert.Throws <ArgumentNullException>(() => adminSvc.CreateUserAsync(null).GetAwaiter().GetResult()); Assert.That(e.Message, Does.Contain("newUserDetails")); }