public async Task ChangeLastLoginAsync(User user) { user.LastLogIn = DateTime.Now; logger.LogInformation($"User {user.Id} LoggedOn at {DateTime.Now}."); await dbcontext.SaveChangesAsync(); }
public async Task IsOpenAsync_ShouldGet_True() { var options = TestUtilities.GetOptions(nameof(IsOpenAsync_ShouldGet_True)); var mockEmailDTOMapper = new Mock <IEmailDTOMapper>().Object; var mockDecodeService = new Mock <IDecodeService>().Object; var mockEncryptService = new Mock <IEncryptService>().Object; var mockLogger = new Mock <ILogger <EmailService> >().Object; var mockEmail = new Mock <Email>().Object; var testId = "testId"; mockEmail.Id = testId; mockEmail.IsOpne = true; var expectedResult = true; using (var actContext = new TBIAppDbContext(options)) { await actContext.Emails.AddAsync(mockEmail); await actContext.SaveChangesAsync(); } using (var assertContext = new TBIAppDbContext(options)) { var emailService = new EmailService(assertContext, mockEmailDTOMapper, mockDecodeService, mockLogger, null, mockEncryptService); var sut = await emailService.IsOpenAsync(testId); Assert.AreEqual(expectedResult, sut); } }
public async Task GetAllEmailsPagesAsync_ShouldGet_True() { var options = TestUtilities.GetOptions(nameof(GetAllEmailsPagesAsync_ShouldGet_True)); var mockEmailDTOMapper = new Mock <IEmailDTOMapper>().Object; var mockDecodeService = new Mock <IDecodeService>().Object; var mockUserStore = new Mock <IUserStore <User> >(); var mockUserManager = new Mock <UserManager <User> >(mockUserStore.Object, null, null, null, null, null, null, null).Object; var mockEncryptService = new Mock <IEncryptService>().Object; var mockLogger = new Mock <ILogger <EmailService> >().Object; var expectedCount = 1; using (var actContext = new TBIAppDbContext(options)) { await actContext.Emails.AddAsync(new Email()); await actContext.Emails.AddAsync(new Email()); await actContext.SaveChangesAsync(); } using (var assertContext = new TBIAppDbContext(options)) { var sut = new EmailService(assertContext, mockEmailDTOMapper, mockDecodeService, mockLogger, null, mockEncryptService); var result = await sut.GetAllEmailsPagesAsync(); Assert.AreEqual(expectedCount, result); } }
public async Task IsOpenAsync_ShouldThrowArgumentNullEx() { var options = TestUtilities.GetOptions(nameof(IsOpenAsync_ShouldThrowArgumentNullEx)); var mockEmailDTOMapper = new Mock <IEmailDTOMapper>().Object; var mockDecodeService = new Mock <IDecodeService>().Object; var mockEncryptService = new Mock <IEncryptService>().Object; var mockUserStore = new Mock <IUserStore <User> >(); var mockUserManager = new Mock <UserManager <User> >(mockUserStore.Object, null, null, null, null, null, null, null).Object; var mockLogger = new Mock <ILogger <EmailService> >().Object; var mockEmail = new Mock <Email>().Object; var testId = string.Empty; mockEmail.Id = "correctTestId"; mockEmail.IsOpne = true; using (var actContext = new TBIAppDbContext(options)) { await actContext.Emails.AddAsync(mockEmail); await actContext.SaveChangesAsync(); } using (var assertContext = new TBIAppDbContext(options)) { var emailService = new EmailService(assertContext, mockEmailDTOMapper, mockDecodeService, mockLogger, mockUserManager, mockEncryptService); var sut = await emailService.IsOpenAsync(testId); } }
public async Task ChangeStatusAsync_ShouldChangeStatus() { var options = TestUtilities.GetOptions(nameof(ChangeStatusAsync_ShouldChangeStatus)); var mockEmailDTOMapper = new Mock <IEmailDTOMapper>().Object; var mockDecodeService = new Mock <IDecodeService>().Object; var mockEncryptService = new Mock <IEncryptService>().Object; var mockUserStore = new Mock <IUserStore <User> >(); var mockUserManager = new Mock <UserManager <User> >( new Mock <IUserStore <User> >().Object, new Mock <IOptions <IdentityOptions> >().Object, new Mock <IPasswordHasher <User> >().Object, new IUserValidator <User> [0], new IPasswordValidator <User> [0], new Mock <ILookupNormalizer>().Object, new Mock <IdentityErrorDescriber>().Object, new Mock <IServiceProvider>().Object, new Mock <ILogger <UserManager <User> > >().Object); var mockLogger = new Mock <ILogger <EmailService> >().Object; var mockEmail = new Mock <Email>().Object; var testId = "testId"; var testStatus = EmailStatusesEnum.New; mockEmail.Id = testId; mockEmail.Status = testStatus; var mockUser = new Mock <User>().Object; var newEmailStatus = EmailStatusesEnum.Open; var expectedResult = newEmailStatus; using (var actContext = new TBIAppDbContext(options)) { await actContext.Emails.AddAsync(mockEmail); await actContext.SaveChangesAsync(); } using (var assertContext = new TBIAppDbContext(options)) { var emailService = new EmailService(assertContext, mockEmailDTOMapper, mockDecodeService, mockLogger, mockUserManager.Object, mockEncryptService); await emailService.ChangeStatusAsync(testId, newEmailStatus, mockUser); var sut = assertContext.Emails.FirstOrDefault(); Assert.AreEqual(expectedResult, sut.Status); } }
public async Task UnLockButtonAsync_ShouldReturnTypeOfBool() { var options = TestUtilities.GetOptions(nameof(UnLockButtonAsync_ShouldReturnTypeOfBool)); var mockEmailDTOMapper = new Mock <IEmailDTOMapper>().Object; var mockDecodeService = new Mock <IDecodeService>().Object; var mockEncryptService = new Mock <IEncryptService>().Object; var userStoreMock = new Mock <IUserStore <User> >(); var mockUserManager = new Mock <UserManager <User> >( new Mock <IUserStore <User> >().Object, new Mock <IOptions <IdentityOptions> >().Object, new Mock <IPasswordHasher <User> >().Object, new IUserValidator <User> [0], new IPasswordValidator <User> [0], new Mock <ILookupNormalizer>().Object, new Mock <IdentityErrorDescriber>().Object, new Mock <IServiceProvider>().Object, new Mock <ILogger <UserManager <User> > >().Object); var mockLogger = new Mock <ILogger <EmailService> >().Object; var mockEmail = new Mock <Email>().Object; var testId = "testId"; mockEmail.Id = testId; mockEmail.IsOpne = true; using (var actContext = new TBIAppDbContext(options)) { await actContext.Emails.AddAsync(mockEmail); await actContext.SaveChangesAsync(); } using (var assertContext = new TBIAppDbContext(options)) { var emailService = new EmailService(assertContext, mockEmailDTOMapper, mockDecodeService, mockLogger, mockUserManager.Object, mockEncryptService); await emailService.UnLockButtonAsync(testId); var email = assertContext.Emails.FirstOrDefault(); var sut = email.IsOpne; Assert.IsInstanceOfType(sut, typeof(bool)); } }
public async Task IsOpenAsync_ShouldGet_False() { var options = TestUtilities.GetOptions(nameof(IsOpenAsync_ShouldGet_False)); var mockEmailDTOMapper = new Mock <IEmailDTOMapper>().Object; var mockDecodeService = new Mock <IDecodeService>().Object; var mockEncryptService = new Mock <IEncryptService>().Object; var mockUserStore = new Mock <IUserStore <User> >(); var mockUserManager = new Mock <UserManager <User> >( new Mock <IUserStore <User> >().Object, new Mock <IOptions <IdentityOptions> >().Object, new Mock <IPasswordHasher <User> >().Object, new IUserValidator <User> [0], new IPasswordValidator <User> [0], new Mock <ILookupNormalizer>().Object, new Mock <IdentityErrorDescriber>().Object, new Mock <IServiceProvider>().Object, new Mock <ILogger <UserManager <User> > >().Object); var mockLogger = new Mock <ILogger <EmailService> >().Object; var mockEmail = new Mock <Email>().Object; var testId = "testId"; mockEmail.Id = testId; mockEmail.IsOpne = false; var expectedResult = false; using (var actContext = new TBIAppDbContext(options)) { await actContext.Emails.AddAsync(mockEmail); await actContext.SaveChangesAsync(); } using (var assertContext = new TBIAppDbContext(options)) { var emailService = new EmailService(assertContext, mockEmailDTOMapper, mockDecodeService, mockLogger, mockUserManager.Object, mockEncryptService); var sut = await emailService.IsOpenAsync(testId); Assert.AreEqual(expectedResult, sut); } }
public async Task GetEmailsPagesByTypeAsync_ShouldGet_True() { var options = TestUtilities.GetOptions(nameof(GetEmailsPagesByTypeAsync_ShouldGet_True)); var mockEmailDTOMapper = new Mock <IEmailDTOMapper>().Object; var decodeService = new Mock <IDecodeService>().Object; var mockUserStore = new Mock <IUserStore <User> >(); var mockUserManager = new Mock <UserManager <User> >( new Mock <IUserStore <User> >().Object, new Mock <IOptions <IdentityOptions> >().Object, new Mock <IPasswordHasher <User> >().Object, new IUserValidator <User> [0], new IPasswordValidator <User> [0], new Mock <ILookupNormalizer>().Object, new Mock <IdentityErrorDescriber>().Object, new Mock <IServiceProvider>().Object, new Mock <ILogger <UserManager <User> > >().Object); var mockLogger = new Mock <ILogger <EmailService> >().Object; var mockEncryptService = new Mock <IEncryptService>().Object; var status = 1; using (var actContext = new TBIAppDbContext(options)) { await actContext.Emails.AddAsync( new Email { Status = (EmailStatusesEnum)status }); await actContext.SaveChangesAsync(); } using (var assertContext = new TBIAppDbContext(options)) { var sut = new EmailService(assertContext, mockEmailDTOMapper, decodeService, mockLogger, mockUserManager.Object, mockEncryptService); var result = await sut.GetEmailsPagesByTypeAsync((EmailStatusesEnum)status); Assert.AreEqual(1, result); }; }
public async Task UnLockButtonAsync_ShouldSetIsOpenToFalse() { var options = TestUtilities.GetOptions(nameof(UnLockButtonAsync_ShouldSetIsOpenToFalse)); var mockEmailDTOMapper = new Mock <IEmailDTOMapper>().Object; var mockDecodeService = new Mock <IDecodeService>().Object; var mockEncryptService = new Mock <IEncryptService>().Object; var mockUserStore = new Mock <IUserStore <User> >(); var mockUserManager = new Mock <UserManager <User> >(mockUserStore.Object, null, null, null, null, null, null, null).Object; var mockLogger = new Mock <ILogger <EmailService> >().Object; var mockEmail = new Mock <Email>().Object; var testId = "testId"; mockEmail.Id = testId; mockEmail.IsOpne = true; var expectedResult = false; using (var actContext = new TBIAppDbContext(options)) { await actContext.Emails.AddAsync(mockEmail); await actContext.SaveChangesAsync(); } using (var assertContext = new TBIAppDbContext(options)) { var emailService = new EmailService(assertContext, mockEmailDTOMapper, mockDecodeService, mockLogger, mockUserManager, mockEncryptService); await emailService.UnLockButtonAsync(testId); var sut = assertContext.Emails.FirstOrDefault(); Assert.AreEqual(expectedResult, sut.IsOpne); } }
public async Task LockButtonAsync_ShouldReturnTypeOfBool() { var options = TestUtilities.GetOptions(nameof(LockButtonAsync_ShouldReturnTypeOfBool)); var mockEmailDTOMapper = new Mock <IEmailDTOMapper>().Object; var mockDecodeService = new Mock <IDecodeService>().Object; var mockEncryptService = new Mock <IEncryptService>().Object; var mockUserStore = new Mock <IUserStore <User> >(); var mockUserManager = new Mock <UserManager <User> >(mockUserStore.Object, null, null, null, null, null, null, null).Object; var mockLogger = new Mock <ILogger <EmailService> >().Object; var mockEmail = new Mock <Email>().Object; var testId = "testId"; mockEmail.Id = testId; mockEmail.IsOpne = false; using (var actContext = new TBIAppDbContext(options)) { await actContext.Emails.AddAsync(mockEmail); await actContext.SaveChangesAsync(); } using (var assertContext = new TBIAppDbContext(options)) { var emailService = new EmailService(assertContext, mockEmailDTOMapper, mockDecodeService, mockLogger, mockUserManager, mockEncryptService); await emailService.LockButtonAsync(testId); var email = assertContext.Emails.FirstOrDefault(); var sut = email.IsOpne; Assert.IsInstanceOfType(sut, typeof(bool)); } }