Esempio n. 1
0
    public void Initialize()
    {
        _repository = new Mock <INStackRepository>(MockBehavior.Strict);
        _repository.Setup(r => r.DoRequestAsync <DataAppOpenWrapper>(It.Is <RestRequest>(s => s.Resource.EndsWith("api/v2/open")), It.IsAny <Action <HttpStatusCode> >()))
        .Returns(GetAppOpenMock);

        var danish         = new TranslationData();
        var defaultSection = new DefaultSection();

        defaultSection.TryAdd("text", "Jeg er på dansk");
        danish.TryAdd("default", defaultSection);

        _danish = new DataMetaWrapper <TranslationData>
        {
            Data = danish,
            Meta = new MetaData
            {
                Language = new Language
                {
                    Direction = LanguageDirection.LRM,
                    Id        = LanguageId,
                    IsBestFit = true,
                    IsDefault = true,
                    Locale    = LanguageLocale,
                    Name      = "Danish"
                },
                Platform = new ResourcePlatform
                {
                    Id   = LanguageId,
                    Slug = NStackPlatform.Web
                }
            }
        };

        _localizeService = new Mock <INStackLocalizeService>(MockBehavior.Strict);
        _localizeService.Setup(r => r.GetResourceAsync <TranslationData>(It.Is <int>(id => id == LanguageId)))
        .Returns(Task.FromResult(_danish));

        var services = new ServiceCollection();

        services.AddMemoryCache();
        var serviceProvider = services.BuildServiceProvider();

        _memoryCache = serviceProvider?.GetService <IMemoryCache>() ?? throw new ArgumentNullException();

        _service = new NStackAppService(_repository.Object, _localizeService.Object, _memoryCache);
    }
Esempio n. 2
0
    public void SetUp()
    {
        _repository = new Mock <INStackRepository>
        {
            DefaultValue = DefaultValue.Empty
        };

        _repository.Setup(r => r.DoRequestAsync <DataWrapper <List <ResourceData> > >(It.Is <RestRequest>(s => s.Resource.EndsWith("platforms/backend")), It.IsAny <Action <HttpStatusCode> >()))
        .Returns(GetLanguageMock);

        _english = new TranslationData();
        var defaultSection = new DefaultSection();

        defaultSection.TryAdd("text", "I'm in English");
        _english.TryAdd("default", defaultSection);

        _repository.Setup(r => r.DoRequestAsync <DataMetaWrapper <TranslationData> >(It.Is <RestRequest>(s => s.Resource.EndsWith($"resources/{_englishLanguage.Id}")), It.IsAny <Action <HttpStatusCode> >()))
        .Returns(Task.FromResult(new DataMetaWrapper <TranslationData> {
            Data = _english
        }));

        _repository.Setup(r => r.DoRequestAsync <DataMetaWrapper <ResourceItem> >(It.Is <RestRequest>(s => s.Resource.EndsWith($"resources/{_englishLanguage.Id}")), It.IsAny <Action <HttpStatusCode> >()))
        .Returns(Task.FromResult(new DataMetaWrapper <ResourceItem> {
            Data = _english
        }));

        _danish = new TranslationData();
        var defaultDanishSection = new DefaultSection();

        defaultDanishSection.TryAdd("text", "Jeg er på dansk");
        _danish.TryAdd("default", defaultDanishSection);

        _repository.Setup(r => r.DoRequestAsync <DataMetaWrapper <TranslationData> >(It.Is <RestRequest>(s => s.Resource.EndsWith($"resources/{_danishLanguage.Id}")), It.IsAny <Action <HttpStatusCode> >()))
        .Returns(Task.FromResult(new DataMetaWrapper <TranslationData> {
            Data = _danish
        }));

        _repository.Setup(r => r.DoRequestAsync <DataMetaWrapper <ResourceItem> >(It.Is <RestRequest>(s => s.Resource.EndsWith($"resources/{_danishLanguage.Id}")), It.IsAny <Action <HttpStatusCode> >()))
        .Returns(Task.FromResult(new DataMetaWrapper <ResourceItem> {
            Data = _danish
        }));

        _service = new NStackLocalizeService(_repository.Object);
    }