Ejemplo n.º 1
0
        public async Task AddListRemove_HappyPath_Ok()
        {
            await using var context = GetTest1Context();

            using var test = new TestFS(Test4ArchiveUrl, BaseTestFolder);

            var settings = JsonConvert.DeserializeObject <AppSettings>(_settingsJson);

            settings.DatasetsPath = Path.Combine(test.TestFolder, DdbFolder);
            _appSettingsMock.Setup(o => o.Value).Returns(settings);
            _authManagerMock.Setup(o => o.IsUserAdmin()).Returns(Task.FromResult(true));
            _authManagerMock.Setup(o => o.IsOwnerOrAdmin(It.IsAny <Dataset>())).Returns(Task.FromResult(true));

            var ddbManager = new DdbManager(_appSettingsMock.Object, _ddbFactoryLogger);

            var webUtils = new WebUtils(_authManagerMock.Object, context, _appSettingsMock.Object,
                                        _httpContextAccessorMock.Object, ddbManager);

            var metaManager = new MetaManager(_metaManagerLogger, ddbManager, _authManagerMock.Object, webUtils);

            var a = await metaManager.Add(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug,
                                          "annotations", "{\"test\":123}");

            a.Data["test"].ToObject <int>().Should().Be(123);

            var res = await metaManager.List(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug);

            res.Should().HaveCount(1);
            res.First().Count.Should().Be(1);
            res.First().Key.Should().Be("annotations");

            var a2 = await metaManager.Add(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug, "annotations",
                                           "{\"test\":4124,\"pippo\":\"ciao\"}");

            a2.Data["test"].ToObject <int>().Should().Be(4124);
            a2.Data["pippo"].ToObject <string>().Should().Be("ciao");

            (await metaManager.List(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug)).Should().HaveCount(1);

            (await metaManager.Get(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug, "annotations"))
            .Should().HaveCount(2);

            (await metaManager.Remove(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug, a.Id)).Should().Be(1);

            (await metaManager.Get(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug, "annotations"))
            .Should().HaveCount(1);

            (await metaManager.Unset(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug, "annotations")).Should().Be(1);

            (await metaManager.List(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug)).Should()
            .BeEmpty();
        }