public async Task WhenAddingApplicationThenUnitOfWorkIsCommitted()
        {
            // Arrange
            IApplicationRepository fakeApplicationRepository = A.Fake <IApplicationRepository>();

            A.CallTo(() => fakeApplicationRepository.TryGetByDisplayNameAsync(A <string> .Ignored)).Returns(Task.FromResult <ApplicationEntity>(null));

            IUnitOfWork fakeUnitOfWork = A.Fake <IUnitOfWork>();

            IPasswordWithSaltHasher fakePasswordHasher = A.Fake <IPasswordWithSaltHasher>();

            A.CallTo(() => fakePasswordHasher.HashPassword(A <string> .Ignored)).Returns(new HashWithSaltResult());

            IApplicationService applicationService = new ApplicationService(fakeApplicationRepository, fakeUnitOfWork, fakePasswordHasher);

            ApplicationCreateDto applicationCreateDto = new ApplicationCreateDto()
            {
                DisplayName = "TestApplicationDisplayName",
                Password    = "******"
            };

            // Act
            await applicationService.AddApplicationAsync(applicationCreateDto);

            // Assert
            A.CallTo(() => fakeUnitOfWork.CommitAsync()).MustHaveHappened();
        }
        public void WhenAddingExistingApplicationThenExceptionIsThrown()
        {
            // Arrange
            IApplicationRepository fakeApplicationRepository = A.Fake <IApplicationRepository>();

            A.CallTo(() => fakeApplicationRepository.TryGetByDisplayNameAsync(A <string> .Ignored)).Returns(Task.FromResult(new ApplicationEntity()));

            IUnitOfWork fakeUnitOfWork = A.Fake <IUnitOfWork>();

            IPasswordWithSaltHasher fakePasswordHasher = A.Fake <IPasswordWithSaltHasher>();

            IApplicationService applicationService = new ApplicationService(fakeApplicationRepository, fakeUnitOfWork, fakePasswordHasher);

            ApplicationCreateDto applicationCreateDto = new ApplicationCreateDto()
            {
                DisplayName = "TestApplicationDisplayName",
                Password    = "******"
            };

            // Act
            ArgumentException ex = Assert.CatchAsync <ArgumentException>(async() => await applicationService.AddApplicationAsync(applicationCreateDto));

            // Assert
            StringAssert.Contains("Application with DisplayName TestApplicationDisplayName already exists.", ex.Message);
        }
        public void WhenAddingApplicationWithEmptyPasswordThenExceptionIsThrown()
        {
            // Arrange
            IApplicationRepository  fakeApplicationRepository = A.Fake <IApplicationRepository>();
            IUnitOfWork             fakeUnitOfWork            = A.Fake <IUnitOfWork>();
            IPasswordWithSaltHasher fakePasswordHasher        = A.Fake <IPasswordWithSaltHasher>();
            IApplicationService     applicationService        = new ApplicationService(fakeApplicationRepository, fakeUnitOfWork, fakePasswordHasher);

            ApplicationCreateDto applicationCreateDto = new ApplicationCreateDto()
            {
                DisplayName = "TestApplicationDisplayName",
                Password    = ""
            };

            // Act
            ArgumentException ex = Assert.CatchAsync <ArgumentException>(async() => await applicationService.AddApplicationAsync(applicationCreateDto));

            // Assert
            StringAssert.Contains("Application name and password must be provided.", ex.Message);
        }
        public void WhenAddingNullApplicationThenExceptionIsThrown()
        {
            // Arrange
            IApplicationRepository  fakeApplicationRepository = A.Fake <IApplicationRepository>();
            IUnitOfWork             fakeUnitOfWork            = A.Fake <IUnitOfWork>();
            IPasswordWithSaltHasher fakePasswordHasher        = A.Fake <IPasswordWithSaltHasher>();
            IApplicationService     applicationService        = new ApplicationService(fakeApplicationRepository, fakeUnitOfWork, fakePasswordHasher);

            // Act
            ArgumentException ex = Assert.CatchAsync <ArgumentException>(async() => await applicationService.AddApplicationAsync(null));

            // Assert
            StringAssert.Contains("Application name and password must be provided.", ex.Message);
        }