public async Task CanGetAllWithAllData()
        {
            TestDataUtil.AddJobWithAllData();

            var actualJobs = await _jobRepository.GetAllWithAllDataAsync();

            actualJobs.Should().BeEquivalentTo(
                TestDataUtil.GetAll<Job>(),
                config => config
                    .Excluding(o => o.Id)
                    .Excluding(o => o.Bonuses)
                    .Excluding(info => info.SelectedMemberPath.EndsWith(".Stat"))
                    .Excluding(info => info.SelectedMemberPath.EndsWith(".Skill"))
                    .IgnoringCyclicReferences());
        }
Exemple #2
0
        public async Task GetHistoryByCharacterIdAsync_ShouldSortResultByDateDescending()
        {
            TestDataUtil
            .AddUser()
            .AddCharacterWithRequiredDependencies()
            .AddCharacterHistoryEntry(h => h.Date = new DateTime(100))
            .AddCharacterHistoryEntry(h => h.Date = new DateTime(300));

            var historyEntries = await _characterRepository.GetHistoryByCharacterIdAsync(TestDataUtil.Get <Character>(0).Id, null, 0, false);

            historyEntries.Select(h => h.Action).Should().BeEquivalentTo(
                TestDataUtil.Get <CharacterHistoryEntry>(1).Action,
                TestDataUtil.Get <CharacterHistoryEntry>(0).Action
                );
        }
        public async Task CanGetEffectCategories()
        {
            TestDataUtil
            .AddEffectType()
            .AddEffectSubCategory()
            .AddEffectSubCategory();

            var actualEffectCategories = await _effectRepository.GetCategoriesAsync();

            actualEffectCategories.Should().BeEquivalentTo(
                TestDataUtil.GetAll <EffectType>(),
                config => config
                .Excluding(o => o.Id)
                .IgnoringCyclicReferences());
        }
Exemple #4
0
        public async Task GetHistoryByCharacterIdAsync_ShouldReturnRequestedPage()
        {
            TestDataUtil
            .AddCharacterWithRequiredDependencies();
            for (var i = 0; i < 41; i++)
            {
                var i1 = i;
                TestDataUtil.AddCharacterHistoryEntry(h => h.Date = new DateTime(i1 * 100));
            }

            var historyEntries = await _characterRepository.GetHistoryByCharacterIdAsync(TestDataUtil.Get <Character>(0).Id, null, 1, false);

            historyEntries.Should().HaveCount(1);
            historyEntries.First().Action.Should().Be(TestDataUtil.Get <CharacterHistoryEntry>(0).Action);
        }
Exemple #5
0
        public void ShouldProperlyRecover()
        {
            var sequentialLargeIds = TestDataUtil.ReadData("non-leaf-page-seq-id-large-values-2.txt");

            var enumerator = sequentialLargeIds.GetEnumerator();

            var options = StorageEnvironmentOptions.ForPath(DataDir);

            options.ManualFlushing = true;

            using (var env = new StorageEnvironment(options))
            {
                for (var transactions = 0; transactions < 100; transactions++)
                {
                    using (var tx = env.WriteTransaction())
                    {
                        var tree = tx.CreateTree("foo");
                        for (var i = 0; i < 100; i++)
                        {
                            enumerator.MoveNext();

                            tree.Add(enumerator.Current.Key.ToString("0000000000000000"), new MemoryStream(enumerator.Current.Value));
                        }

                        tx.Commit();
                    }

                    if (transactions == 50)
                    {
                        env.FlushLogToDataFile();
                    }
                }

                ValidateRecords(env, new List <string> {
                    "foo"
                }, sequentialLargeIds.Select(x => x.Key.ToString("0000000000000000")).ToList());
            }

            options = StorageEnvironmentOptions.ForPath(DataDir);
            options.ManualFlushing = true;

            using (var env = new StorageEnvironment(options))
            {
                ValidateRecords(env, new List <string> {
                    "foo"
                }, sequentialLargeIds.Select(x => x.Key.ToString("0000000000000000")).ToList());
            }
        }
Exemple #6
0
        public async Task GetForSummaryByOwnerIdAsync_ShouldNotReturnsCharacterThatDoesNotBelongToTheUser()
        {
            TestDataUtil
            .AddJob()
            .AddOrigin();

            TestDataUtil.AddUser();
            var notOwnerUser = TestDataUtil.GetLast <User>();

            TestDataUtil.AddUser()
            .AddCharacter(TestDataUtil.GetLast <User>().Id);

            var characters = await _characterRepository.GetForSummaryByOwnerIdAsync(notOwnerUser.Id);

            characters.Should().BeEmpty();
        }
        public async Task GetAllWithAllData()
        {
            TestDataUtil.AddOriginWithAllData();
            var origins = TestDataUtil.GetAll <Origin>();

            var actualOrigins = await _originRepository.GetAllWithAllDataAsync();

            actualOrigins.Should().BeEquivalentTo(
                origins,
                config => config
                .Excluding(o => o.Id)
                .Excluding(info => info.SelectedMemberPath.EndsWith(".Stat"))
                .Excluding(info => info.SelectedMemberPath.EndsWith(".Skill"))
                .IgnoringCyclicReferences()
                );
        }
        public async void UpdateSubstatus_SetInitialSubstatus_ReturnsUpdatedInstance()
        {
            // Arrange
            string    org = "tdd";
            string    app = "endring-av-navn";
            int       instanceOwnerPartyId = 1337;
            string    instanceGuid         = "66233fb5-a9f2-45d4-90b1-f6d93ad40713";
            Substatus expectedSubstatus    = new Substatus {
                Label = "Substatus.Approved.Label", Description = "Substatus.Approved.Description"
            };

            TestDataUtil.PrepareInstance(org, app, instanceOwnerPartyId, new Guid(instanceGuid));

            HttpClient client = SetupUtil.GetTestClient(_factory, org, app);

            string token = PrincipalUtil.GetOrgToken("tdd");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            string             requestUri         = $"/{org}/{app}/instances/{instanceOwnerPartyId}/{instanceGuid}/substatus";
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, requestUri);

            httpRequestMessage.Content = new StringContent(
                JsonConvert.SerializeObject(new Substatus
            {
                Label       = "Substatus.Approved.Label",
                Description = "Substatus.Approved.Description"
            }),
                Encoding.UTF8,
                "application/json");

            // Act
            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            TestDataUtil.DeleteInstance(org, app, instanceOwnerPartyId, new Guid(instanceGuid));

            string json = await response.Content.ReadAsStringAsync();

            Instance updatedInstance = JsonConvert.DeserializeObject <Instance>(json);

            // Assert
            Assert.NotNull(updatedInstance);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(expectedSubstatus.Label, updatedInstance.Status.Substatus.Label);
            Assert.Equal(expectedSubstatus.Description, updatedInstance.Status.Substatus.Description);
            Assert.True(updatedInstance.LastChanged > DateTime.UtcNow.AddMinutes(-5));
        }
Exemple #9
0
        public async void Instance_Post_WithMultipartPrefill()
        {
            /* SETUP */
            string instanceOwnerPartyId = "1337";

            Instance instanceTemplate = new Instance()
            {
                InstanceOwner = new InstanceOwner
                {
                    PartyId = instanceOwnerPartyId,
                }
            };

            string instance = JsonConvert.SerializeObject(instanceTemplate);
            string xml      = File.ReadAllText("Data/Files/data-element.xml");

            string boundary = "abcdefgh";
            MultipartFormDataContent formData = new MultipartFormDataContent(boundary)
            {
                { new StringContent(instance, Encoding.UTF8, "application/json"), "instance" },
                { new StringContent(xml, Encoding.UTF8, "application/xml"), "default" }
            };

            Uri uri = new Uri("/tdd/endring-av-navn/instances", UriKind.Relative);

            /* TEST */

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", "endring-av-navn");
            string     token  = PrincipalUtil.GetToken(1337);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            HttpResponseMessage response = await client.PostAsync(uri, formData);

            response.EnsureSuccessStatusCode();

            Assert.True(response.StatusCode == HttpStatusCode.Created);

            Instance createdInstance = JsonConvert.DeserializeObject <Instance>(await response.Content.ReadAsStringAsync());

            Assert.NotNull(createdInstance);
            Assert.Single(createdInstance.Data);
            Assert.Equal("default", createdInstance.Data[0].DataType);

            TestDataUtil.DeleteInstanceAndData("tdd", "endring-av-navn", 1337, new Guid(createdInstance.Id.Split('/')[1]));
        }
Exemple #10
0
        public async Task GetHistoryByCharacterIdAsync_ShouldReturnsGroupHistory_MoreRecentThanTheLatestChararacterHistoryWhenRequestingPage0()
        {
            TestDataUtil
            .AddUser()
            .AddGroup()
            .AddCharacterWithRequiredDependencies(c => c.Group = TestDataUtil.GetLast <Group>())
            .AddCharacterHistoryEntry(h => h.Date = new DateTime(100))
            .AddGroupHistoryEntry(h => h.Date     = new DateTime(200));

            var character      = TestDataUtil.Get <Character>();
            var historyEntries = await _characterRepository.GetHistoryByCharacterIdAsync(character.Id, character.GroupId, 0, false);

            historyEntries.Select(c => c.Action).Should().BeEquivalentTo(
                TestDataUtil.GetLast <GroupHistoryEntry>().Action,
                TestDataUtil.GetLast <CharacterHistoryEntry>().Action
                );
        }
Exemple #11
0
        public async Task GetHistoryByCharacterIdAsync_ShouldNotReturnsEntryOfOtherGroups()
        {
            TestDataUtil
            .AddUser()
            .AddGroup()
            .AddGroupHistoryEntry(h => h.Date = new DateTime(200))
            .AddGroup()
            .AddCharacterWithRequiredDependencies(c => c.Group = TestDataUtil.GetLast <Group>())
            .AddCharacterHistoryEntry(h => h.Date = new DateTime(100))
            .AddCharacterHistoryEntry(h => h.Date = new DateTime(400));

            var character = TestDataUtil.Get <Character>();

            var historyEntries = await _characterRepository.GetHistoryByCharacterIdAsync(character.Id, character.GroupId, 0, false);

            historyEntries.OfType <GroupHistoryEntry>().Should().BeEmpty();
        }
Exemple #12
0
        public async Task GetWithOwnerAsync_ShouldLoadAllRelatedDataUsedForCharacterPermissionCheck()
        {
            TestDataUtil.AddItemTemplateAndRequiredData();
            TestDataUtil.AddGroupWithRequiredData();
            var user      = TestDataUtil.AddUser().GetLast <User>();
            var character = TestDataUtil.AddOrigin().AddCharacter(user.Id, u => u.Group = TestDataUtil.GetLast <Group>()).GetLast <Character>();

            TestDataUtil.AddItem(character);

            var item = await _itemRepository.GetWithOwnerAsync(TestDataUtil.Get <Item>().Id);

            var expectation = TestDataUtil.GetLast <Item>();

            item.Should().BeEquivalentTo(expectation, config => config.ExcludingChildren());
            item.Character.Should().BeEquivalentTo(TestDataUtil.GetLast <Character>(), config => config.ExcludingChildren());
            item.Character.Group.Should().BeEquivalentTo(TestDataUtil.GetLast <Group>(), config => config.ExcludingChildren());
        }
        public async Task Proceess_End_AfterNext_OK()
        {
            TestDataUtil.DeleteInstanceAndData("tdd", "endring-av-navn", 1337, new System.Guid("26233fb5-a9f2-45d4-90b1-f6d93ad40713"));
            TestDataUtil.PrepareInstance("tdd", "endring-av-navn", 1337, new System.Guid("26233fb5-a9f2-45d4-90b1-f6d93ad40713"));
            string token = PrincipalUtil.GetToken(1337);

            string instancePath = "/tdd/endring-av-navn/instances/1337/26233fb5-a9f2-45d4-90b1-f6d93ad40713";

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", "endring-av-navn");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, $"{instancePath}/process/start");

            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, $"{instancePath}/process/completeProcess");

            response = await client.SendAsync(httpRequestMessage);

            responseContent = await response.Content.ReadAsStringAsync();

            response.EnsureSuccessStatusCode();

            ProcessState status = JsonConvert.DeserializeObject <ProcessState>(responseContent);

            Assert.NotNull(status.Ended);
            Assert.Null(status.CurrentTask);


            httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, $"{instancePath}");
            response           = await client.SendAsync(httpRequestMessage);

            responseContent = await response.Content.ReadAsStringAsync();

            response.EnsureSuccessStatusCode();

            Instance resultInstance = JsonConvert.DeserializeObject <Instance>(responseContent);

            Assert.Equal(1, resultInstance.Data.Count);

            TestDataUtil.DeleteInstanceAndData("tdd", "endring-av-navn", 1337, new System.Guid("26233fb5-a9f2-45d4-90b1-f6d93ad40713"));
        }
        public async void Post_RegistrationOfEventsTurnedOn_ControllerCallsEventWithCorrectType()
        {
            string org     = "ttd";
            string app     = "events";
            int    partyId = 1337;

            Instance instanceTemplate = new Instance
            {
                InstanceOwner = new InstanceOwner
                {
                    PartyId = partyId.ToString(),
                }
            };

            HttpClient client = SetupUtil.GetTestClient(_factory, org, app);

            string token = PrincipalUtil.GetToken(partyId);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            StringContent content = new StringContent(instanceTemplate.ToString(), Encoding.UTF8);

            content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, $"/{org}/{app}/instances")
            {
                Content = content
            };

            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            response.EnsureSuccessStatusCode();

            Instance createdInstance = JsonConvert.DeserializeObject <Instance>(responseContent);

            Assert.Equal(partyId.ToString(), createdInstance.InstanceOwner.PartyId);

            //// Commented out the Asserts as another test might clear the Requests list and then fail these.
            ////Assert.Equal("app.instance.created", EventsMockSI.Requests.First().eventType);
            ////Assert.NotNull(EventsMockSI.Requests.First().instance);

            TestDataUtil.DeleteInstanceAndData(org, app, partyId, new Guid(createdInstance.Id.Split('/')[1]));
        }
        public async void Instance_Post_NabovarselWithMessageAndForm()
        {
            // Arrange
            string instanceOwnerPartyId = "1337";

            Instance instanceTemplate = new Instance()
            {
                InstanceOwner = new InstanceOwner
                {
                    PartyId = instanceOwnerPartyId,
                }
            };

            string instance   = JsonConvert.SerializeObject(instanceTemplate);
            string xml        = File.ReadAllText("Data/Files/SvarPaaNabovarselType.xml");
            string xmlmelding = File.ReadAllText("Data/Files/melding.xml");

            string boundary = "abcdefgh";
            MultipartFormDataContent formData = new MultipartFormDataContent(boundary)
            {
                { new StringContent(instance, Encoding.UTF8, "application/json"), "instance" },
                { new StringContent(xml, Encoding.UTF8, "application/xml"), "skjema" },
                { new StringContent(xmlmelding, Encoding.UTF8, "application/xml"), "melding" }
            };

            Uri uri = new Uri("/dibk/nabovarsel/instances", UriKind.Relative);

            // ACT
            HttpClient client = SetupUtil.GetTestClient(_factory, "dibk", "nabovarsel");
            string     token  = PrincipalUtil.GetOrgToken("dibk");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            HttpResponseMessage response = await client.PostAsync(uri, formData);

            // Assert
            response.EnsureSuccessStatusCode();
            Assert.True(response.StatusCode == HttpStatusCode.Created);

            Instance createdInstance = JsonConvert.DeserializeObject <Instance>(await response.Content.ReadAsStringAsync());

            Assert.NotNull(createdInstance);
            Assert.Equal(2, createdInstance.Data.Count);
            TestDataUtil.DeleteInstanceAndData("dibk", "nabovarsel", 1337, new Guid(createdInstance.Id.Split('/')[1]));
        }
        public async Task Proceess_Start_OK()
        {
            TestDataUtil.DeleteInstanceAndData("tdd", "endring-av-navn", 1337, new System.Guid("26233fb5-a9f2-45d4-90b1-f6d93ad40713"));
            TestDataUtil.PrepareInstance("tdd", "endring-av-navn", 1337, new System.Guid("26233fb5-a9f2-45d4-90b1-f6d93ad40713"));
            string token = PrincipalUtil.GetToken(1337);

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", "endring-av-navn");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "/tdd/endring-av-navn/instances/1337/26233fb5-a9f2-45d4-90b1-f6d93ad40713/process/start");

            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            TestDataUtil.DeleteInstanceAndData("tdd", "endring-av-navn", 1337, new System.Guid("26233fb5-a9f2-45d4-90b1-f6d93ad40713"));
        }
        public async Task Proceess_Start_With_Prefill_OK()
        {
            TestDataUtil.DeleteInstanceAndData("tdd", "endring-av-navn", 1337, new System.Guid("26233fb5-a9f2-45d4-90b1-f6d93ad40713"));
            TestDataUtil.PrepareInstance("tdd", "endring-av-navn", 1337, new System.Guid("26233fb5-a9f2-45d4-90b1-f6d93ad40713"));
            string token = PrincipalUtil.GetToken(1337);

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", "endring-av-navn");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "/tdd/endring-av-navn/instances/1337/26233fb5-a9f2-45d4-90b1-f6d93ad40713/process/start")
            {
            };

            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            // fetch instance and get data element id
            httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, $"/tdd/endring-av-navn/instances/1337/26233fb5-a9f2-45d4-90b1-f6d93ad40713/")
            {
            };
            response = await client.SendAsync(httpRequestMessage);

            Instance    instance    = JsonConvert.DeserializeObject <Instance>(await response.Content.ReadAsStringAsync());
            DataElement dataElement = instance.Data.First();

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            // fetch actual data and compare to expected prefill
            httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, $"/tdd/endring-av-navn/instances/1337/26233fb5-a9f2-45d4-90b1-f6d93ad40713/data/{dataElement.Id}")
            {
            };
            response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            var skjema = JsonConvert.DeserializeObject <App.IntegrationTests.Mocks.Apps.tdd.endring_av_navn.Skjema>(responseContent);

            Assert.Equal(skjema.Tilknytninggrp9315.TilknytningTilNavnetgrp9316.TilknytningMellomnavn2grp9353.PersonMellomnavnAndreTilknyttetGardNavndatadef34931.value, "01039012345");
            Assert.Equal(skjema.Tilknytninggrp9315.TilknytningTilNavnetgrp9316.TilknytningMellomnavn2grp9353.PersonMellomnavnAndreTilknyttetPersonsEtternavndatadef34930.value, "Oslo");
            Assert.Equal(skjema.Tilknytninggrp9315.TilknytningTilNavnetgrp9316.TilknytningMellomnavn2grp9353.PersonMellomnavnAndreTilknytningBeskrivelsedatadef34928.value, "Grev Wedels Plass");
            TestDataUtil.DeleteInstanceAndData("tdd", "endring-av-navn", 1337, new System.Guid("26233fb5-a9f2-45d4-90b1-f6d93ad40713"));
        }
Exemple #18
0
        public async void Get_DataElement_Org_Ok()
        {
            TestDataUtil.DeleteInstanceAndDataAndBlobs(1337, "ca9da17c-904a-44d2-9771-a5420acfbcf3", "tdd", "endring-av-navn");
            TestDataUtil.PrepareInstance(1337, new Guid("ca9da17c-904a-44d2-9771-a5420acfbcf3"), "tdd", "endring-av-navn");
            DataElement dataElementBefore = TestDataUtil.GetDataElement("28023597-516b-4a71-a77c-d3736912abd5");
            string      dataPathWithData  = $"{_versionPrefix}/instances/1337/ca9da17c-904a-44d2-9771-a5420acfbcf3/data/28023597-516b-4a71-a77c-d3736912abd5";

            HttpClient client = GetTestClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("tdd"));
            HttpResponseMessage response = await client.GetAsync($"{dataPathWithData}");

            DataElement dataElementAfter = TestDataUtil.GetDataElement("28023597-516b-4a71-a77c-d3736912abd5");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Null(dataElementBefore.AppOwner);
            Assert.NotNull(dataElementAfter.AppOwner);
            TestDataUtil.DeleteInstanceAndDataAndBlobs(1337, "ca9da17c-904a-44d2-9771-a5420acfbcf3", "tdd", "endring-av-navn");
        }
Exemple #19
0
        public async Task Data_Put_PresentationTextsUpdated_ExistingValueOverwritten()
        {
            // Arrange
            int    expectedCount = 1;
            string expectedValue = "Andreas Dahl";
            string expectedKey   = "Title";
            string org           = "ttd";
            string app           = "presentationfields-app";
            string instanceGuid  = "447ed22d-67a8-42c7-8add-cc35eba304f1";
            string dataGuid      = "590ebc27-246e-4a0a-aea3-4296cb231d78";
            string token         = PrincipalUtil.GetToken(1337);

            TestDataUtil.PrepareInstance(org, app, 1337, new Guid(instanceGuid));

            HttpClient client = SetupUtil.GetTestClient(_factory, org, app);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            string requestUri  = $"/{org}/{app}/instances/1337/{instanceGuid}/data/{dataGuid}?dataType=default";
            string requestBody = "{\"skjemanummer\":\"1472\",\"spesifikasjonsnummer\":\"9812\",\"blankettnummer\":\"AFP-01\",\"tittel\":\"ArbeidsgiverskjemaAFP\",\"gruppeid\":\"8818\",\"OpplysningerOmArbeidstakerengrp8819\":{\"Arbeidsforholdgrp8856\":{\"AnsattSammenhengendeAnsattAnsettelsedatadef33267\":{\"value\":\"Andreas Dahl\",\"orid\":\"33267\"}}}}";

            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, requestUri)
            {
                Content = new StringContent(requestBody, Encoding.UTF8, "application/json")
            };

            // Act
            await client.SendAsync(httpRequestMessage);

            HttpResponseMessage res = await client.GetAsync($"/{org}/{app}/instances/1337/{instanceGuid}");

            TestDataUtil.DeleteInstanceAndData(org, app, 1337, new Guid(instanceGuid));

            string responseContent = await res.Content.ReadAsStringAsync();

            Instance instance = JsonConvert.DeserializeObject <Instance>(responseContent);

            // Assert
            Assert.Equal(HttpStatusCode.OK, res.StatusCode);
            Assert.Equal(expectedCount, instance.PresentationTexts.Count);
            Assert.True(instance.PresentationTexts.ContainsKey(expectedKey));
            Assert.Equal(expectedValue, instance.PresentationTexts[expectedKey]);
        }
Exemple #20
0
        public async Task GetHistoryByCharacterIdAsync_ShouldSortGroupAndCharacterResultByDateDescending()
        {
            TestDataUtil
            .AddUser()
            .AddGroup()
            .AddCharacterWithRequiredDependencies(c => c.Group = TestDataUtil.GetLast <Group>())
            .AddCharacterHistoryEntry(h => h.Date = new DateTime(100))
            .AddGroupHistoryEntry(h => h.Date     = new DateTime(200))
            .AddCharacterHistoryEntry(h => h.Date = new DateTime(300));

            var character      = TestDataUtil.Get <Character>(0);
            var historyEntries = await _characterRepository.GetHistoryByCharacterIdAsync(character.Id, character.GroupId, 0, false);

            historyEntries.Select(h => h.Action).Should().BeEquivalentTo(
                TestDataUtil.Get <CharacterHistoryEntry>(1).Action,
                TestDataUtil.Get <GroupHistoryEntry>(0).Action,
                TestDataUtil.Get <CharacterHistoryEntry>(0).Action
                );
        }
Exemple #21
0
        public async Task CanGetAllWithEffects()
        {
            var skills = TestDataUtil
                         .AddSkill()
                         .AddSkill()
                         .GetAll <Skill>();

            var actualSkills = await _skillRepository.GetAllWithEffectsAsync();

            actualSkills.Should().BeEquivalentTo(
                skills,
                config => config
                .Excluding(s => s.Id)
                .Excluding(s => s.JobSkills)
                .Excluding(s => s.OriginSkills)
                .Excluding(info => info.SelectedMemberPath == "Skill")
                .IgnoringCyclicReferences()
                );
        }
Exemple #22
0
        public async Task GetWithAllDataAsync_ShouldLoadExpectedCharacter_WithAllExpectedData()
        {
            TestDataUtil.AddUser();
            var user = TestDataUtil.GetLast <User>();

            TestDataUtil.AddCharacterWithAllData(user.Id);
            var expectedCharacter = TestDataUtil.GetLast <Character>();

            TestDataUtil.AddGroupInvite(expectedCharacter, TestDataUtil.GetLast <Group>(), true);

            var character = await _characterRepository.GetWithAllDataAsync(expectedCharacter.Id);

            character.Should().BeEquivalentTo(expectedCharacter, config => config.ExcludingChildren());
            character.Jobs.Select(x => x.JobId).Should().BeEquivalentTo(TestDataUtil.GetAll <Job>().Select(x => x.Id));
            character.Specialities.Select(x => x.Speciality).Should().BeEquivalentTo(TestDataUtil.GetAll <Speciality>(), config => config.ExcludingChildren());
            character.Group.Should().BeEquivalentTo(TestDataUtil.GetLast <Group>(), config => config.ExcludingChildren());
            character.Modifiers.Should().BeEquivalentTo(expectedCharacter.Modifiers, config => config.ExcludingChildren());
            character.Invites.Should().BeEquivalentTo(TestDataUtil.GetAll <GroupInvite>(), config => config.ExcludingChildren());
            character.Invites.First().Group.Should().BeEquivalentTo(TestDataUtil.Get <Group>(), config => config.ExcludingChildren());
        }
Exemple #23
0
        public void ReadAllSegments()
        {
            var segments = ReadSegments("Data/withExifAndIptc.jpg");

            Assert.Equal(13, segments.Count);

            Assert.Equal(JpegSegmentType.App0, segments[0].Type);
            Assert.Equal(JpegSegmentType.App1, segments[1].Type);
            Assert.Equal(JpegSegmentType.AppD, segments[2].Type);
            Assert.Equal(JpegSegmentType.App1, segments[3].Type);
            Assert.Equal(JpegSegmentType.App2, segments[4].Type);
            Assert.Equal(JpegSegmentType.AppE, segments[5].Type);

            Assert.Equal(TestDataUtil.GetBytes("Data/withExifAndIptc.jpg.app0"), segments[0].Bytes);
            Assert.Equal(TestDataUtil.GetBytes("Data/withExifAndIptc.jpg.app1.0"), segments[1].Bytes);
            Assert.Equal(TestDataUtil.GetBytes("Data/withExifAndIptc.jpg.appd"), segments[2].Bytes);
            Assert.Equal(TestDataUtil.GetBytes("Data/withExifAndIptc.jpg.app1.1"), segments[3].Bytes);
            Assert.Equal(TestDataUtil.GetBytes("Data/withExifAndIptc.jpg.app2"), segments[4].Bytes);
            Assert.Equal(TestDataUtil.GetBytes("Data/withExifAndIptc.jpg.appe"), segments[5].Bytes);
        }
        public async Task GetByGroupIdAsync_FullyLoadLootAndItems()
        {
            var expectedLoot                = TestDataUtil.AddLoot(l => l.IsVisibleForPlayer = true).GetLast <Loot>();
            var expectedLootItemTemplate    = TestDataUtil.AddItemTemplateSection().AddItemTemplateSubCategory().AddItemTemplate().GetLast <ItemTemplate>();
            var expectedLootItem            = TestDataUtil.AddItem(expectedLoot).GetLast <Item>();
            var expectedMonster             = TestDataUtil.AddMonster(c => c.Loot = expectedLoot).GetLast <Monster>();
            var expectedMonsterItemTemplate = TestDataUtil.AddItemTemplate().GetLast <ItemTemplate>();
            var expectedMonsterItem         = TestDataUtil.AddItem(expectedMonster).GetLast <Item>();

            var loots = await _lootRepository.GetByGroupIdAsync(_group.Id);

            var loot = loots.First();

            loot.Should().BeEquivalentTo(expectedLoot, config => config.Excluding(l => l.Items).Excluding(l => l.Monsters).Excluding(l => l.Group));
            loot.Items.First().Should().BeEquivalentTo(expectedLootItem, config => config.Excluding(i => i.ItemTemplate).Excluding(i => i.Character).Excluding(i => i.Loot));
            loot.Items.First().ItemTemplate.Should().BeEquivalentTo(expectedLootItemTemplate, config => config.Excluding(i => i.SubCategory).Excluding(i => i.Requirements).Excluding(i => i.Modifiers).Excluding(i => i.SkillModifiers).Excluding(i => i.UnSkills).Excluding(i => i.Slots).Excluding(i => i.Skills));
            loot.Monsters.First().Should().BeEquivalentTo(expectedMonster, config => config.Excluding(m => m.Items).Excluding(m => m.Group).Excluding(m => m.Loot));
            loot.Monsters.First().Items.First().Should().BeEquivalentTo(expectedMonsterItem, config => config.Excluding(i => i.ItemTemplate).Excluding(i => i.Monster));
            loot.Monsters.First().Items.First().ItemTemplate.Should().BeEquivalentTo(expectedMonsterItemTemplate, config => config.Excluding(i => i.SubCategory).Excluding(i => i.Requirements).Excluding(i => i.Modifiers).Excluding(i => i.SkillModifiers).Excluding(i => i.UnSkills).Excluding(i => i.Slots).Excluding(i => i.Skills));
        }
        public void ValidatePart_MissingContentType()
        {
            // Arrange
            Application app      = TestDataUtil.GetApplication("ttd", "events");
            string      partName = "hundebilde";

            RequestPart part = new RequestPart
            {
                Name = partName
            };

            string expectedErrorMessage = $"The multipart section named {partName} is missing Content-Type.";
            RequestPartValidator sut    = new RequestPartValidator(app);

            // Act
            string actual = sut.ValidatePart(part);

            // Assert
            Assert.Equal(expectedErrorMessage, actual);
        }
        public void ValidatePart_InvalidDataType()
        {
            // Arrange
            Application app      = TestDataUtil.GetApplication("ttd", "events");
            string      partName = "kattebilde";

            RequestPart part = new RequestPart
            {
                Name = partName
            };

            string expectedErrorMessage = $"Multipart section named, '{partName}' does not correspond to an element type in application metadata";
            RequestPartValidator sut    = new RequestPartValidator(app);

            // Act
            string actual = sut.ValidatePart(part);

            // Assert
            Assert.Equal(expectedErrorMessage, actual);
        }
        public async Task Data_Post_With_Prefill_Org_OK()
        {
            Guid guid = new Guid("37133fb5-a9f2-45d4-90b1-f6d93ad40713");

            TestDataUtil.DeleteDataForInstance("tdd", "endring-av-navn", 500600, guid);

            string token = PrincipalUtil.GetToken(1337);

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", "endring-av-navn");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            // Fetch data element
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, $"/tdd/endring-av-navn/instances/500600/{guid}/data?dataType=default")
            {
            };
            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            DataElement dataElement = JsonConvert.DeserializeObject <DataElement>(responseContent);

            // Fetch data and compare with expected prefill
            httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, $"/tdd/endring-av-navn/instances/500600/{guid}/data/{dataElement.Id}")
            {
            };
            response = await client.SendAsync(httpRequestMessage);

            responseContent = await response.Content.ReadAsStringAsync();

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var skjema = JsonConvert.DeserializeObject <App.IntegrationTests.Mocks.Apps.tdd.endring_av_navn.Skjema>(responseContent);

            Assert.Equal("Sofies Gate 2", skjema.Tilknytninggrp9315.TilknytningTilNavnetgrp9316.TilknytningMellomnavn2grp9353.PersonMellomnavnAndreTilknyttetGardNavndatadef34931.value);
            Assert.Equal("EAS Health Consulting", skjema.Tilknytninggrp9315.TilknytningTilNavnetgrp9316.TilknytningMellomnavn2grp9353.PersonMellomnavnAndreTilknyttetPersonsEtternavndatadef34930.value);
            Assert.Equal("http://setrabrl.no", skjema.Tilknytninggrp9315.TilknytningTilNavnetgrp9316.TilknytningMellomnavn2grp9353.PersonMellomnavnAndreTilknytningBeskrivelsedatadef34928.value);

            TestDataUtil.DeleteDataForInstance("tdd", "endring-av-navn", 500600, guid);
        }
        public async Task Instance_Post_InstansiateWithoutAddingData()
        {
            string token = PrincipalUtil.GetToken(1337);

            HttpClient client = SetupUtil.GetTestClient(_factory, "tdd", "sirius");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "/tdd/sirius/instances?instanceOwnerPartyId=1337");

            HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

            string responseContent = await response.Content.ReadAsStringAsync();

            Instance instance = JsonConvert.DeserializeObject <Instance>(responseContent);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            Assert.NotNull(instance);
            Assert.Equal("1337", instance.InstanceOwner.PartyId);

            TestDataUtil.DeleteInstanceAndData("tdd", "sirius", 1337, new Guid(instance.Id.Split('/')[1]));
        }
        public void ValidatePart_ValidateInstance_ValidInstance()
        {
            // Arrange
            Application app         = TestDataUtil.GetApplication("ttd", "events");
            string      partName    = "instance";
            string      contentType = "application/json";

            RequestPart part = new RequestPart
            {
                Name        = partName,
                ContentType = contentType,
            };

            RequestPartValidator sut = new RequestPartValidator(app);

            // Act
            var actual = sut.ValidatePart(part);

            // Assert
            Assert.Null(actual);
        }
        protected override void Initialize(IViewContext context)
        {
            _pathInfo     = new PathInfo();
            _imageService = new ImageService(_pathInfo);
            _imageService.ExtractFlags();


            ActivationChanged += OnActivationChanged;


            _eventAggregator = SdlTradosStudio.Application.GetService <IStudioEventAggregator>();
            _eventAggregator.GetEvent <StudioWindowCreatedNotificationEvent>()?.Subscribe(OnStudioWindowCreatedNotificationEvent);

            _projectsController = SdlTradosStudio.Application.GetController <ProjectsController>();
            //var project = _projectsController.CurrentProject.GetProjectInfo();

            // TODO this will be replaced with a call to recover the relevant data from the projects loaded in Studio
            var testDataUtil = new TestDataUtil(_imageService);

            _projectModels = testDataUtil.GetTestProjectData();
        }