public void Should_update_languages()
        {
            var newLanguageName1 = "New Language Name 1";
            var newLanguageName2 = "New Language Name 2";

            var languageToUpdate1 = LanguageFactory.Language(_siteId, _languageId1, newLanguageName1, "ab1", "ab1");
            var languageToUpdate2 = LanguageFactory.Language(_siteId, _languageId2, newLanguageName2, "ab2", "ab2");

            using (var context = new MSSQLDbContext(_contextOptions))
            {
                var repository = new LanguageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                repository.Update(new List <Language> {
                    languageToUpdate1, languageToUpdate2
                });
            }

            using (var context = new MSSQLDbContext(_contextOptions))
            {
                var repository       = new LanguageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var updatedLanguage1 = repository.GetById(_siteId, _languageId1);

                Assert.AreEqual(newLanguageName1, updatedLanguage1.Name);
            }

            using (var context = new MSSQLDbContext(_contextOptions))
            {
                var repository       = new LanguageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var updatedLanguage2 = repository.GetById(_siteId, _languageId2);

                Assert.AreEqual(newLanguageName2, updatedLanguage2.Name);
            }
        }
Beispiel #2
0
        public void Should_update_language()
        {
            const string newLanguageName = "New Language Name 1";

            var languageToUpdate         = LanguageFactory.Language(_siteId, _languageId1, newLanguageName, "en", "en");
            var languageToUpdateDbEntity = new LanguageDbEntity
            {
                SiteId      = languageToUpdate.SiteId,
                Id          = languageToUpdate.Id,
                Name        = languageToUpdate.Name,
                CultureName = languageToUpdate.CultureName
            };

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <LanguageDbEntity>(languageToUpdate)).Returns(languageToUpdateDbEntity);
            mapperMock.Setup(x => x.Map <Language>(languageToUpdateDbEntity)).Returns(languageToUpdate);

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

            _sut.Update(languageToUpdate);

            var updatedLanguage = _sut.GetById(_siteId, _languageId1);

            Assert.AreEqual(newLanguageName, updatedLanguage.Name);
        }
Beispiel #3
0
        public void Should_save_new_language()
        {
            var newLanguage = LanguageFactory.Language();

            _sut.Create(newLanguage);

            var actual = _sut.GetById(_siteId, newLanguage.Id);

            Assert.NotNull(actual);
        }
Beispiel #4
0
        public void Should_update_language()
        {
            var newLanguageName = "New Language Name 1";

            var languageToUpdate = LanguageFactory.Language(_siteId, _languageId1, newLanguageName, "en", "en");

            _sut.Update(languageToUpdate);

            var updatedLanguage = _sut.GetById(_siteId, _languageId1);

            Assert.AreEqual(newLanguageName, updatedLanguage.Name);
        }
Beispiel #5
0
        public void SetUp()
        {
            var optionsBuilder = new DbContextOptionsBuilder <WeapsyDbContext>();

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

            _siteId      = Guid.NewGuid();
            _languageId1 = Guid.NewGuid();
            _languageId2 = Guid.NewGuid();

            _dbContext.Set <LanguageDbEntity>().AddRange(
                new LanguageDbEntity
            {
                SiteId      = _siteId,
                Id          = _languageId1,
                Name        = "Language Name 1",
                CultureName = "ab1",
                Url         = "ab1",
                Status      = LanguageStatus.Active
            },
                new LanguageDbEntity
            {
                SiteId      = _siteId,
                Id          = _languageId2,
                Name        = "Language Name 2",
                CultureName = "ab2",
                Url         = "ab2",
                Status      = LanguageStatus.Hidden
            },
                new LanguageDbEntity
            {
                Status = LanguageStatus.Deleted
            }
                );

            _dbContext.SaveChanges();

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <LanguageDbEntity>(It.IsAny <Language>())).Returns(new LanguageDbEntity());
            mapperMock.Setup(x => x.Map <Language>(It.IsAny <LanguageDbEntity>())).Returns(new Language());
            mapperMock.Setup(x => x.Map <ICollection <Language> >(It.IsAny <ICollection <LanguageDbEntity> >())).Returns(new List <Language>
            {
                LanguageFactory.Language(_siteId, _languageId1, "Name", "CultureName", "Url"),
                LanguageFactory.Language(_siteId, _languageId2, "Name", "CultureName", "Url")
            });

            _sut = new LanguageRepository(_dbContext, mapperMock.Object);
        }
        public void Should_save_new_language()
        {
            var newLanguage = LanguageFactory.Language(_siteId, Guid.NewGuid(), "Name", "CultureName", "Url");

            using (var context = new MSSQLDbContext(_contextOptions))
            {
                var repository = new LanguageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                repository.Create(newLanguage);
            }

            using (var context = new MSSQLDbContext(_contextOptions))
            {
                var repository = new LanguageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var language   = repository.GetById(_siteId, newLanguage.Id);

                Assert.NotNull(language);
            }
        }
Beispiel #7
0
        public void Should_update_languages()
        {
            var newLanguageName1 = "New Language Name 1";
            var newLanguageName2 = "New Language Name 2";

            var languageToUpdate1 = LanguageFactory.Language(_siteId, _languageId1, newLanguageName1, "ab1", "ab1");
            var languageToUpdate2 = LanguageFactory.Language(_siteId, _languageId2, newLanguageName2, "ab2", "ab2");

            _sut.Update(new List <Language> {
                languageToUpdate1, languageToUpdate2
            });

            var updatedLanguage1 = _sut.GetById(_siteId, _languageId1);
            var updatedLanguage2 = _sut.GetById(_siteId, _languageId2);

            Assert.AreEqual(newLanguageName1, updatedLanguage1.Name);
            Assert.AreEqual(newLanguageName2, updatedLanguage2.Name);
        }
Beispiel #8
0
        public void Setup()
        {
            _siteId     = Guid.NewGuid();
            _languageId = Guid.NewGuid();

            var language = LanguageFactory.Language(_siteId, _languageId, "", "", "");

            var repositoryMock = new Mock <ILanguageRepository>();

            repositoryMock.Setup(x => x.GetById(_siteId, _languageId)).Returns(language);
            repositoryMock.Setup(x => x.GetAll(_siteId)).Returns(new List <Language> {
                language
            });

            var cacheManagerMock = new Mock <ICacheManager>();

            _sut = new LanguageFacade(repositoryMock.Object, cacheManagerMock.Object, Shared.CreateNewMapper());
        }
        public void Should_update_language()
        {
            const string newLanguageName = "New Language Name 1";

            var languageToUpdate = LanguageFactory.Language(_siteId, _languageId1, newLanguageName, "en", "en");

            using (var context = new MSSQLDbContext(_contextOptions))
            {
                var repository = new LanguageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                repository.Update(languageToUpdate);
            }

            using (var context = new MSSQLDbContext(_contextOptions))
            {
                var repository      = new LanguageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var updatedLanguage = repository.GetById(_siteId, _languageId1);

                Assert.AreEqual(newLanguageName, updatedLanguage.Name);
            }
        }
Beispiel #10
0
        public void Should_save_new_language()
        {
            var newLanguage         = LanguageFactory.Language(_siteId, Guid.NewGuid(), "Name", "CultureName", "Url");
            var newLanguageDbEntity = new LanguageDbEntity
            {
                SiteId      = newLanguage.SiteId,
                Id          = newLanguage.Id,
                Name        = newLanguage.Name,
                CultureName = newLanguage.CultureName
            };

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <LanguageDbEntity>(newLanguage)).Returns(newLanguageDbEntity);
            mapperMock.Setup(x => x.Map <Language>(newLanguageDbEntity)).Returns(newLanguage);

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

            _sut.Create(newLanguage);

            var actual = _sut.GetById(_siteId, newLanguage.Id);

            Assert.NotNull(actual);
        }