Esempio n. 1
0
        public void Should_save_new_theme()
        {
            var newTheme = ThemeFactory.Theme(Guid.NewGuid(), "Name 3", "Description 3", "Folder 3");

            _sut.Create(newTheme);

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

            Assert.NotNull(actual);
        }
Esempio n. 2
0
        public void Should_update_theme()
        {
            var newThemeDescription = "New Description 1";

            var themeToUpdate = ThemeFactory.Theme(_themeId1, "Name 1", newThemeDescription, "Folder 1");

            _sut.Update(themeToUpdate);

            var updatedTheme = _sut.GetById(_themeId1);

            Assert.AreEqual(newThemeDescription, updatedTheme.Description);
        }
Esempio n. 3
0
        public void SetUp()
        {
            var optionsBuilder = new DbContextOptionsBuilder <WeapsyDbContext>();

            optionsBuilder.UseInMemoryDatabase();
            _dbContext = new WeapsyDbContext(optionsBuilder.Options);

            _themeId1 = Guid.NewGuid();
            _themeId2 = Guid.NewGuid();

            _dbContext.Set <ThemeDbEntity>().AddRange
            (
                new ThemeDbEntity
            {
                Id          = _themeId1,
                Name        = "Name 1",
                Description = "Description 1",
                Folder      = "Folder 1",
                Status      = ThemeStatus.Active
            },
                new ThemeDbEntity
            {
                Id          = _themeId2,
                Name        = "Name 2",
                Description = "Description 2",
                Folder      = "Folder 2",
                Status      = ThemeStatus.Active
            },
                new ThemeDbEntity
            {
                Status = ThemeStatus.Deleted
            }
            );

            _dbContext.SaveChanges();

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

            mapperMock.Setup(x => x.Map <ThemeDbEntity>(It.IsAny <Theme>())).Returns(new ThemeDbEntity());
            mapperMock.Setup(x => x.Map <Theme>(It.IsAny <ThemeDbEntity>())).Returns(new Theme());
            mapperMock.Setup(x => x.Map <ICollection <Theme> >(It.IsAny <ICollection <ThemeDbEntity> >())).Returns(new List <Theme>
            {
                ThemeFactory.Theme(_themeId1, "Name", "Description", "Folder"),
                ThemeFactory.Theme(_themeId2, "Name", "Description", "Folder")
            });

            _sut = new ThemeRepository(_dbContext, mapperMock.Object);
        }
Esempio n. 4
0
        public void Should_save_new_theme()
        {
            var newTheme = ThemeFactory.Theme(Guid.NewGuid(), "Name 3", "Description 3", "Folder 3");

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new ThemeRepository(Shared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                repository.Create(newTheme);
            }

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new ThemeRepository(Shared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var theme      = repository.GetById(newTheme.Id);

                Assert.NotNull(theme);
            }
        }
Esempio n. 5
0
        public void Should_update_theme()
        {
            const string newThemeDescription = "New Description 1";

            var themeToUpdate = ThemeFactory.Theme(_themeId1, "Name 1", newThemeDescription, "Folder 1");

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new ThemeRepository(Shared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                repository.Update(themeToUpdate);
            }

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository   = new ThemeRepository(Shared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var updatedTheme = repository.GetById(_themeId1);

                Assert.AreEqual(newThemeDescription, updatedTheme.Description);
            }
        }
Esempio n. 6
0
        public void Should_save_new_theme()
        {
            var newTheme         = ThemeFactory.Theme(Guid.NewGuid(), "Name 3", "Description 3", "Folder 3");
            var newThemeDbEntity = new ThemeDbEntity
            {
                Id          = newTheme.Id,
                Name        = newTheme.Name,
                Description = newTheme.Description,
                Folder      = newTheme.Folder
            };

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <ThemeDbEntity>(newTheme)).Returns(newThemeDbEntity);
            mapperMock.Setup(x => x.Map <Theme>(newThemeDbEntity)).Returns(newTheme);

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

            _sut.Create(newTheme);

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

            Assert.NotNull(actual);
        }