示例#1
0
        public void SaveBulletins_Should_Include_Date()
        {
            Bulletin bulletin = new Bulletin()
            {
                Id       = 123,
                Title    = "TestTitle",
                Content  = "TestContent",
                AuthorId = "12345"
            };

            var claimsUser = new ClaimsPrincipal(
                new ClaimsIdentity(
                    new Claim[] {
                new Claim(ClaimTypes.Name, "fakeusername")
            })
                );

            ApplicationUser user = new ApplicationUser()
            {
                Id = "1235"
            };

            Mock <UserManager <ApplicationUser> > userManager = MockUserManager <ApplicationUser>();

            userManager.Setup(x => x.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(user);

            Bulletin bulletinSaved = new Bulletin();
            Mock <IBulletinRepository> mockRepository = new Mock <IBulletinRepository>();

            mockRepository.Setup(x => x.SaveBulletin(bulletin))
            .Returns((Bulletin bulletinPassed) => { return(bulletinPassed); })
            .Callback((Bulletin bulletinPassedIn) =>
            {
                bulletinSaved = bulletin;
            });

            BulletinManager manager = new BulletinManager(mockRepository.Object, userManager.Object);

            Bulletin actualBulletin = manager.SaveNewBulletin(bulletin, claimsUser);

            mockRepository.Verify(x => x.SaveBulletin(bulletin), Times.Once);
            Assert.AreEqual(DateTime.Now.ToShortDateString(), actualBulletin.CreatedDate.ToShortDateString());
        }
示例#2
0
        public void SaveBulletins_Should_Include_AuthorId()
        {
            Bulletin bulletin = new Bulletin()
            {
                Id      = 123,
                Title   = "TestTitle",
                Content = "TestContent"
            };

            var claimsUser = new ClaimsPrincipal(
                new ClaimsIdentity(
                    new Claim[] {
                new Claim(ClaimTypes.Name, "fakeusername")
            })
                );

            ApplicationUser user = new ApplicationUser()
            {
                Id = "1235"
            };

            Mock <UserManager <ApplicationUser> > userManager = MockUserManager <ApplicationUser>();

            userManager.Setup(x => x.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(user);

            Bulletin bulletinSaved = new Bulletin()
            {
                Id       = bulletin.Id,
                Title    = bulletin.Title,
                Content  = bulletin.Content,
                AuthorId = user.Id
            };
            Mock <IBulletinRepository> mockRepository = new Mock <IBulletinRepository>();

            mockRepository.Setup(x => x.SaveBulletin(bulletin)).Returns(bulletinSaved);

            BulletinManager manager = new BulletinManager(mockRepository.Object, userManager.Object);

            manager.SaveNewBulletin(bulletin, claimsUser);

            mockRepository.Verify(x => x.SaveBulletin(bulletin), Times.Once);
            Assert.AreEqual(user.Id, bulletinSaved.AuthorId);
        }
示例#3
0
        public void SaveBulletins_Should_Save_Notification()
        {
            int expectedCount = 5;

            Bulletin bulletin = new Bulletin()
            {
                Id          = 123,
                CreatedDate = DateTime.Now,
                Title       = "TestTitle",
                Content     = "TestContent",
                AuthorId    = "12345"
            };

            var claimsUser = new ClaimsPrincipal(
                new ClaimsIdentity(
                    new Claim[] {
                new Claim(ClaimTypes.Name, "fakeusername")
            })
                );

            ApplicationUser user = new ApplicationUser()
            {
                Id = "1235"
            };

            Mock <UserManager <ApplicationUser> > userManager = MockUserManager <ApplicationUser>();

            userManager.Setup(x => x.GetUserAsync(claimsUser)).ReturnsAsync(user);

            Mock <IBulletinRepository> mockRepository = new Mock <IBulletinRepository>();

            mockRepository.Setup(x => x.SaveBulletin(It.IsAny <Bulletin>()))
            .Returns((Bulletin bulletinSaved) => { return(bulletinSaved); });

            BulletinManager manager = new BulletinManager(mockRepository.Object, userManager.Object);

            manager.SaveNewBulletin(bulletin, claimsUser);

            mockRepository.Verify(x => x.SaveBulletin(bulletin), Times.Once);
        }