Exemplo n.º 1
0
        public void WebSite_DeleteTest()
        {
            var webSiteRepositoryMock = new Mock<IWebSiteRepository>();
            var webSiteMock = new Mock<WebSite>();
            webSiteMock.Object.Id = 1;
            webSiteMock.Object.SiteName = "www.google.com";
            webSiteMock.Object.Template = "<test>";

            webSiteRepositoryMock.Setup(repository => repository.Delete(webSiteMock.Object));

            WebSiteUnitOfWork unitOfWork = new WebSiteUnitOfWork(webSiteRepositoryMock.Object);
            unitOfWork.Delete(webSiteMock.Object);

            webSiteRepositoryMock.Verify(repository => repository.Delete(webSiteMock.Object), Times.Exactly(1));
        }
Exemplo n.º 2
0
        public void WebSite_CreateTest()
        {
            var webSiteRepositoryMock = new Mock<IWebSiteRepository>();
            var webSiteMock = new Mock<WebSite>();
            webSiteMock.Object.Id = 1;
            webSiteMock.Object.SiteName = "www.google.com";
            webSiteMock.Object.Template = "<Test Data>";

            webSiteRepositoryMock.Setup(repository => repository.Save(webSiteMock.Object))
                .Returns(webSiteMock.Object);

            WebSiteUnitOfWork uow = new WebSiteUnitOfWork(webSiteRepositoryMock.Object);
            WebSite webSite = uow.Save(webSiteMock.Object);

            webSiteRepositoryMock.Verify(repository => repository.Save(webSiteMock.Object), Times.Exactly(1));
            Assert.IsTrue(webSite == webSiteMock.Object);
        }
Exemplo n.º 3
0
        public void WebSite_GetById()
        {
            var webSiteRepositoryMock = new Mock<IWebSiteRepository>();
            var webSiteMock = new Mock<WebSite>();
            webSiteMock.Object.Id = 0;
            webSiteMock.Object.SiteName = "www.google.com";
            webSiteMock.Object.Template = "<test>";

            webSiteRepositoryMock.Setup(repository => repository.GetById(It.Is<long>(id => id > 0 && id < 6)))
                    .Returns(webSiteMock.Object);

            WebSiteUnitOfWork unitOfWork = new WebSiteUnitOfWork(webSiteRepositoryMock.Object);
            for (long i = 1; i <= 2; i++)
            {
                unitOfWork.GetById(i);
            }

            webSiteRepositoryMock.Verify(repository => repository.GetById(It.Is<long>(id => id > 0 && id < 6)), Times.Exactly(2));
        }
Exemplo n.º 4
0
        public void WebSiteEMails_List()
        {
            var webSiteRepositoryMock = new Mock<IWebSiteRepository>();
            List<WebSiteEMails> emails = new List<WebSiteEMails>();

            webSiteRepositoryMock.Setup(repository => repository.GetWebSiteEMails(1))
                    .Returns(emails.AsQueryable());

            WebSiteUnitOfWork unitOfWork = new WebSiteUnitOfWork(webSiteRepositoryMock.Object);
            IList<WebSiteEMails> list = unitOfWork.GetWebSiteEMails(1);

            webSiteRepositoryMock.Verify(repository => repository.GetWebSiteEMails(1), Times.AtLeastOnce());
            Assert.True(list.Count == 0);
        }
Exemplo n.º 5
0
        public void WebSite_List()
        {
            var webSiteRepositoryMock = new Mock<IWebSiteRepository>();
            List<WebSite> webSites = new List<WebSite>();

            webSiteRepositoryMock.Setup(repository => repository.List)
                    .Returns(webSites.AsQueryable());

            WebSiteUnitOfWork unitOfWork = new WebSiteUnitOfWork(webSiteRepositoryMock.Object);
            List<WebSite> webSiteList = unitOfWork.List;

            webSiteRepositoryMock.Verify(repository => repository.List, Times.AtLeastOnce());
            Assert.True(webSiteList.Count == 0);
        }