Beispiel #1
0
        public async Task ThrowException_WhenPassedUsernameIsNull()
        {
            var options = TestUtils.GetOptions(nameof(ThrowException_WhenPassedUsernameIsNull));

            using (var assertContext = new CMContext(options))
            {
                var sut = new NotificationServices(assertContext, _userServices.Object,
                                                   _iNotificationManager.Object);
                var ex = await Assert.ThrowsExceptionAsync <MagicException>(
                    async() => await sut.CreateNotificationAsync("23", null));
            }
        }
Beispiel #2
0
        public async Task ThrowCorrectMessage_WhenPassedDescriptionIsNull()
        {
            var options = TestUtils.GetOptions(nameof(ThrowCorrectMessage_WhenPassedDescriptionIsNull));

            using (var assertContext = new CMContext(options))
            {
                var sut = new NotificationServices(assertContext, _userServices.Object,
                                                   _iNotificationManager.Object);
                var ex = await Assert.ThrowsExceptionAsync <MagicException>(
                    async() => await sut.CreateNotificationAsync(null, "5"));

                Assert.AreEqual(ExceptionMessages.DescriptionNull, ex.Message);
            }
        }
Beispiel #3
0
        public async Task AddNotificationToAdmin_WhenValidParametersArePassed()
        {
            var userStoreMocked = new Mock <IUserStore <AppUser> >();
            var userManagerMock =
                new Mock <UserManager <AppUser> >
                    (userStoreMocked.Object, null, null, null, null, null, null, null, null);
            var adminName   = "pesho";
            var id          = "1";
            var description = "new";
            var userName    = "******";

            var options = TestUtils.GetOptions(nameof(AddNotificationToAdmin_WhenValidParametersArePassed));
            var admin   = new AppUser
            {
                Id       = id,
                UserName = adminName
            };
            var roles = new List <string> {
                "Admin"
            };

            _userServices.Setup(x => x.GetAdmin())
            .ReturnsAsync(admin);

            using (var arrangeContext = new CMContext(options))
            {
                var sut = new NotificationServices(arrangeContext, _userServices.Object,
                                                   _iNotificationManager.Object);

                arrangeContext.Add(admin);
                //var managerRole = new AppRole { Id = "1", Name = "Manager", NormalizedName = "MANAGER" };
                var adminRole = new AppRole {
                    Id = "2", Name = "Admin", NormalizedName = "ADMIN"
                };
                //arrangeContext.Roles.Add(managerRole);
                arrangeContext.Roles.Add(adminRole);
                await arrangeContext.SaveChangesAsync();

                var result = await sut.CreateNotificationAsync(description, userName);

                Assert.AreEqual(id, arrangeContext.Notifications.First().UserId);
                Assert.AreEqual(description, arrangeContext.Notifications.First().Description);
                Assert.AreEqual(userName, arrangeContext.Notifications.First().Username);
                Assert.AreNotEqual(null, arrangeContext.Notifications.First().EventDate);
            }
        }