public async Task ReturnRoles_Successfully()
        {
            var options = TestUtils.GetOptions(nameof(ReturnRoles_Successfully));

            var testUserRole = "Manager";
            var testRoleId   = "TestRoleId";

            using (var arrangeContext = new EmailManagerDbContext(options))
            {
                await arrangeContext.Roles.AddAsync(new IdentityRole { Id = testRoleId, Name = testUserRole });

                await arrangeContext.SaveChangesAsync();
            }

            var userStoreMock = new Mock <IUserStore <User> >();

            var mockUserManager = new Mock <UserManager <User> >(userStoreMock.Object, null, null, null, null, null, null, null, null);



            using (var assertContext = new EmailManagerDbContext(options))
            {
                var sut = new UsersService(assertContext, mockUserManager.Object);

                var roles = await sut.GetRolesAsync();

                Assert.AreEqual(testRoleId, roles.First().Id);
            }
        }
Beispiel #2
0
        public async Task ReturnCorrectEmailStatusById_WhenPassedValueIsCorrect()
        {
            var testStatus = "TestStatus";
            var options    = TestUtils.GetOptions(nameof(ReturnCorrectEmailStatusById_WhenPassedValueIsCorrect));
            var status     = new StatusEmail()
            {
                StatusType = testStatus
            };

            using (var arrangeContext = new EmailManagerDbContext(options))
            {
                await arrangeContext.StatusEmails.AddAsync(status);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new EmailManagerDbContext(options))
            {
                var sut = new EmailStatusService(assertContext);

                var result = await sut.GetEmailStatusByIdAsync(status.Id);

                Assert.AreEqual(status.Id, result.Id);
            }
        }
        public async Task ReturnCorrectUser_WhenPassedValueIsCorrect()
        {
            var testUsername = "******";

            var newUser = new User()
            {
                UserName = testUsername
            };

            var options = TestUtils.GetOptions(nameof(ReturnCorrectUser_WhenPassedValueIsCorrect));

            using (var arrangeContext = new EmailManagerDbContext(options))
            {
                await arrangeContext.Users.AddAsync(newUser);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new EmailManagerDbContext(options))
            {
                var userStoreMock = new Mock <IUserStore <User> >();

                var mockUserManager = new Mock <UserManager <User> >(userStoreMock.Object, null, null, null, null, null, null, null, null);
                var sut             = new UsersService(assertContext, mockUserManager.Object);

                var result = await sut.GetUserByIdAsync(newUser.Id);

                Assert.AreEqual(newUser.Id, result.Id);
            }
        }
        public async Task ReturnClientDataNull_WhenPassedValueNotMatch()
        {
            var testFirstName = "TestName";
            var options       = TestUtils.GetOptions(nameof(ReturnClientDataNull_WhenPassedValueNotMatch));
            var clientData    = new ClientData()
            {
                FirstName = testFirstName
            };

            var mockValidation = new Mock <IValidation>().Object;
            var mockEncryption = new Mock <IEncryptingHelper>().Object;

            using (var arrangeContext = new EmailManagerDbContext(options))
            {
                await arrangeContext.ClientDatas.AddAsync(clientData);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new EmailManagerDbContext(options))
            {
                var sut = new ClientService(assertContext, mockValidation, mockEncryption);

                var result = await sut.GetClientDataByIdAsync("invalid");

                Assert.IsNull(result);
            }
        }
Beispiel #5
0
        public async Task ReturnAttchmentsType_Successfully()
        {
            var options = TestUtils.GetOptions(nameof(ReturnAttchmentsType_Successfully));

            var testAttachmentId = "Attachment";

            var newAttachment = new EmailAttachments()
            {
                Id = testAttachmentId
            };

            using (var arrangeContext = new EmailManagerDbContext(options))
            {
                await arrangeContext.EmailAttachments.AddAsync(newAttachment);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new EmailManagerDbContext(options))
            {
                var sut    = new AttachmentsService(assertContext);
                var result = await sut.GetEmailAttachmentsByEmailIdAsync(testAttachmentId);

                Assert.IsInstanceOfType(result, typeof(ICollection <EmailAttachmentsDTO>));
            }
        }
Beispiel #6
0
        public async Task ReturnCorrectEmailById_WhenPassedValueIsCorrect()
        {
            var testBody = "TestBody";
            var options  = TestUtils.GetOptions(nameof(ReturnCorrectEmailById_WhenPassedValueIsCorrect));
            var email    = new ClientEmail()
            {
                Body = testBody
            };

            var mockEmailFactory  = new Mock <IEmailFactory>().Object;
            var mockEmailStatus   = new Mock <IEmailStatusService>().Object;
            var mockEncryptHelper = new Mock <IEncryptingHelper>();

            using (var arrangeContext = new EmailManagerDbContext(options))
            {
                await arrangeContext.Emails.AddAsync(email);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new EmailManagerDbContext(options))
            {
                var sut = new EmailService(assertContext, mockEmailFactory, mockEncryptHelper.Object, mockEmailStatus);

                mockEncryptHelper.Setup(e => e.Encrypt("")).Returns("");
                mockEncryptHelper.Setup(e => e.Encrypt("")).Returns("");
                mockEncryptHelper.Setup(e => e.Decrypt("")).Returns("");
                mockEncryptHelper.Setup(e => e.Decrypt("")).Returns("");

                var result = await sut.GetEmailByIdAsync(email.Id);

                Assert.AreEqual(email.Id, result.Id);
            }
        }
        public async Task ReturnEmailsType_Successfully()
        {
            var testBody   = "TestBody";
            var options    = TestUtils.GetOptions(nameof(ReturnEmailsType_Successfully));
            var firstEmail = new ClientEmail()
            {
                Body = testBody
            };

            var mockEmailFactory  = new Mock <IEmailFactory>().Object;
            var mockEmailStatus   = new Mock <IEmailStatusService>().Object;
            var mockEncryptHelper = new Mock <EncryptingHelper>().Object;

            using (var arrangeContext = new EmailManagerDbContext(options))
            {
                await arrangeContext.Emails.AddAsync(firstEmail);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new EmailManagerDbContext(options))
            {
                var sut = new EmailService(assertContext, mockEmailFactory, mockEncryptHelper, mockEmailStatus);

                var result = await sut.GetAllEmailsAsync();

                Assert.IsInstanceOfType(result, typeof(ICollection <EmailDTO>));
            }
        }
        public async Task ReturnClientDataType_Successfully()
        {
            var firstName = "FirstName";
            var lastName  = "LastName";
            var egn       = "1234567899";

            var options    = TestUtils.GetOptions(nameof(FindClient_Successfully));
            var clientData = new ClientData()
            {
                FirstName = firstName, LastName = lastName, EGN = egn
            };

            var mockValidation = new Mock <IValidation>().Object;
            var mockEncryption = new Mock <IEncryptingHelper>();

            using (var arrangeContext = new EmailManagerDbContext(options))
            {
                await arrangeContext.ClientDatas.AddAsync(clientData);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new EmailManagerDbContext(options))
            {
                var sut = new ClientService(assertContext, mockValidation, mockEncryption.Object);
                mockEncryption.Setup(e => e.Encrypt(lastName)).Returns(lastName);
                mockEncryption.Setup(e => e.Encrypt(egn)).Returns(egn);
                mockEncryption.Setup(e => e.Decrypt(lastName)).Returns(lastName);
                mockEncryption.Setup(e => e.Decrypt(egn)).Returns(egn);
                var data = await sut.FindClientAsync(firstName, lastName, egn);

                Assert.IsInstanceOfType(data, typeof(ClientDataDTO));
            }
        }
        public async Task ReturnCorrectEmail_WhenExists()
        {
            var testId  = "TestId";
            var options = TestUtils.GetOptions(nameof(ReturnCorrectEmail_WhenExists));
            var email   = new ClientEmail()
            {
                OriginalMailId = testId
            };

            var mockEmailFactory  = new Mock <IEmailFactory>().Object;
            var mockEmailStatus   = new Mock <IEmailStatusService>().Object;
            var mockEncryptHelper = new Mock <EncryptingHelper>().Object;

            using (var arrangeContext = new EmailManagerDbContext(options))
            {
                await arrangeContext.Emails.AddAsync(email);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new EmailManagerDbContext(options))
            {
                var sut = new EmailService(assertContext, mockEmailFactory, mockEncryptHelper, mockEmailStatus);

                var result = await sut.CheckIfEmailExists(testId);

                Assert.AreEqual(true, result);
            }
        }
        public async Task ReturnCollectionOfEmail()
        {
            var testBody   = "TestBody";
            var options    = TestUtils.GetOptions(nameof(ReturnCollectionOfEmail));
            var firstEmail = new ClientEmail()
            {
                Body = testBody
            };
            var secondEmail = new ClientEmail()
            {
                Body = "SecondBodyName"
            };
            var thirdEmail = new ClientEmail()
            {
                Body = "ThirdBodyName"
            };

            var mockEmailFactory  = new Mock <IEmailFactory>().Object;
            var mockEmailStatus   = new Mock <IEmailStatusService>().Object;
            var mockEncryptHelper = new Mock <EncryptingHelper>().Object;


            using (var arrangeContext = new EmailManagerDbContext(options))
            {
                await arrangeContext.Emails.AddAsync(firstEmail);

                await arrangeContext.Emails.AddAsync(secondEmail);

                await arrangeContext.Emails.AddAsync(thirdEmail);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new EmailManagerDbContext(options))
            {
                var sut = new EmailService(assertContext, mockEmailFactory, mockEncryptHelper, mockEmailStatus);

                var result = await sut.GetAllEmailsAsync();

                Assert.AreEqual(3, result.Count);
            }
        }