Пример #1
0
        public void Should_save_new_site()
        {
            var newSite = SiteFactory.Site(Guid.NewGuid(), "Name 3");

            _sut.Create(newSite);

            var actual = _sut.GetById(newSite.Id);

            Assert.NotNull(actual);
        }
Пример #2
0
        public void Should_update_site()
        {
            var newSiteName = "New Title 1";

            var siteToUpdate = SiteFactory.Site(_siteId1, newSiteName);

            _sut.Update(siteToUpdate);

            var updatedSite = _sut.GetById(_siteId1);

            Assert.AreEqual(newSiteName, updatedSite.Title);
        }
Пример #3
0
        public void SetUp()
        {
            var optionsBuilder = new DbContextOptionsBuilder <WeapsyDbContext>();

            optionsBuilder.UseInMemoryDatabase();
            var dbContext = new WeapsyDbContext(optionsBuilder.Options);

            _siteId1 = Guid.NewGuid();
            _siteId2 = Guid.NewGuid();

            dbContext.Set <SiteDbEntity>().AddRange(
                new SiteDbEntity
            {
                Id     = _siteId1,
                Name   = "Name 1",
                Title  = "Title 1",
                Url    = "Url 1",
                Status = SiteStatus.Active
            },
                new SiteDbEntity
            {
                Id     = _siteId2,
                Name   = "Name 2",
                Title  = "Title 2",
                Url    = "Url 2",
                Status = SiteStatus.Active
            },
                new SiteDbEntity
            {
                Status = SiteStatus.Deleted
            }
                );

            dbContext.SaveChanges();

            var mapperMock = new Mock <AutoMapper.IMapper>();

            mapperMock.Setup(x => x.Map <SiteDbEntity>(It.IsAny <Site>())).Returns(new SiteDbEntity());
            mapperMock.Setup(x => x.Map <Site>(It.IsAny <SiteDbEntity>())).Returns(new Site());
            mapperMock.Setup(x => x.Map <IList <Site> >(It.IsAny <IList <SiteDbEntity> >())).Returns(new List <Site>
            {
                SiteFactory.Site(_siteId1, "Name"),
                SiteFactory.Site(_siteId2, "Name")
            });

            _sut = new SiteRepository(dbContext, mapperMock.Object);
        }
Пример #4
0
        public void Should_save_new_site()
        {
            var newSite         = SiteFactory.Site(Guid.NewGuid(), "Name 3");
            var newSiteDbEntity = new SiteDbEntity
            {
                Id   = newSite.Id,
                Name = newSite.Name
            };

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <SiteDbEntity>(newSite)).Returns(newSiteDbEntity);
            mapperMock.Setup(x => x.Map <Site>(newSiteDbEntity)).Returns(newSite);

            _sut = new SiteRepository(_dbContext, mapperMock.Object);

            _sut.Create(newSite);

            var actual = _sut.GetById(newSite.Id);

            Assert.NotNull(actual);
        }