public ImportLocaleStringListHandler(IUnitOfWorkFactory unitOfWorkFactory, LocaleStringSerializer serializer, ILocaleStringImporter importer) { _unitOfWorkFactory = unitOfWorkFactory; _serializer = serializer; _importer = importer; }
public async Task ExportLocaleStringList_Should_ReturnStream() { // arrange var cancellationToken = new CancellationToken(); var localeStringSerializer = new LocaleStringSerializer(); var repository = new Mock <IRepository <LocaleString> >(); repository .Setup(x => x.Search(It.IsAny <ExportLocaleStringList>(), It.IsAny <CancellationToken>())) .ReturnsAsync(() => new SearchResult <LocaleString> { Rows = new List <LocaleString> { new LocaleString { Locale = "en", Module = "common", Key = "key1", Value = "value1" }, new LocaleString { Locale = "en", Module = "common", Key = "key2", Value = "value2" }, new LocaleString { Locale = "en", Module = "common", Key = "key3", Value = "value3" }, } }); var handler = new ExportLocaleStringListHandler(repository.Object, localeStringSerializer); // act var result = await handler.Handle(new ExportLocaleStringList { Locale = "en", Module = "common" }, cancellationToken); // assert Assert.IsNotNull(result); Assert.IsNotNull(result.ContentType); Assert.IsNotNull(result.FileName); using (var reader = new StreamReader(result.Stream)) { var expected = File.ReadAllText("../../../Content/locale-strings-en-common-test-1.json"); var json = reader.ReadToEnd().Replace("\r\n", "\n"); Assert.AreEqual(expected, json); } }
public async Task Deserialize_Should_ReturnData() { // arrange var cancellationToken = new CancellationToken(); var json = File.ReadAllText("../../../Content/locale-strings-en-common-test-1.json"); var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)); var serializer = new LocaleStringSerializer(); // act var result = await serializer.Deserialize(stream, cancellationToken); // assert Assert.IsNotNull(result); Assert.IsNotNull(result.Single(x => x.Locale == "en")); Assert.IsNotNull(result.Single(x => x.Locale == "en").Modules.Single(x => x.Module == "common")); Assert.AreEqual(3, result.Single(x => x.Locale == "en").Modules.Single(x => x.Module == "common").Items.Count); }
public ExportLocaleStringListHandler(IRepository <LocaleString> repository, LocaleStringSerializer serializer) { _repository = repository; _serializer = serializer; }