/// <summary> /// Run events related to instantiation /// </summary> /// <remarks> /// For example custom prefill. /// </remarks> /// <param name="instance">Instance information</param> /// <param name="data">The data object created</param> public async Task DataCreation(Instance instance, object data) { if (data.GetType() == typeof(Skjema)) { Skjema model = (Skjema)data; int partyId; if (int.TryParse(instance.InstanceOwner.PartyId, out partyId)) { Party party = await _registerService.GetParty(partyId); model.Innledninggrp9309 = new Innledninggrp9309() { Kontaktinformasjongrp9311 = new Kontaktinformasjongrp9311() { MelderFultnavn = new MelderFultnavn() { value = party.Name } } }; } } await Task.CompletedTask; }
public async Task HentSkjemaOK() { //Arrange var skjema1 = new Skjema { id = 1, navn = "Nordman", mail = "*****@*****.**", spørsmål = "Hei, kunne dere senket prisene i Corona tiden?" }; var skjemaListe = new List <Skjema>(); skjemaListe.Add(skjema1); mockAdmin.Setup(k => k.HentStilteSpørsmål()).ReturnsAsync(skjemaListe); var faqController = new FAQController(mockAdmin.Object, mockAdminLogg.Object); //Act var resultat = await faqController.HentStilteSpørsmål() as OkObjectResult; //Assert Assert.Equal <List <Skjema> >((List <Skjema>)resultat.Value, skjemaListe); }
public void GetDataElementWithDataGuid() { /* SETUP */ Instance instance = new Instance() { Id = $"{instanceOwnerId}/{instanceGuid}", InstanceOwnerId = $"{instanceOwnerId}", AppId = $"{org}/{app}", Org = org, Data = new List <DataElement>() { new DataElement() { Id = $"{dataGuid}", ElementType = "default", ContentType = "application/xml", } } }; Mock <HttpRequest> request = MockRequest(); var context = new Mock <HttpContext>(); context.SetupGet(x => x.Request).Returns(request.Object); context.SetupGet(x => x.User).Returns(MockUser().Object); Mock <IInstance> instanceServiceMock = new Mock <IInstance>(); instanceServiceMock .Setup(i => i.GetInstance(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <Guid>())) .Returns(Task.FromResult(instance)); Stream dataStream = File.OpenRead("Runtime/data/data-element.xml"); Mock <IData> dataServiceMock = new Mock <IData>(); dataServiceMock .Setup(d => d.GetData(org, app, instanceOwnerId, instanceGuid, dataGuid)) .Returns(Task.FromResult(dataStream)); /* TEST */ DataController dataController = NewDataController(context, instanceServiceMock, dataServiceMock); ActionResult result = dataController.Get(org, app, instanceOwnerId, instanceGuid, dataGuid).Result; Assert.IsType <FileStreamResult>(result); FileStreamResult okresult = result as FileStreamResult; Stream resultStream = (Stream)okresult.FileStream; XmlSerializer serializer = new XmlSerializer(typeof(Skjema)); Skjema model = (Skjema)serializer.Deserialize(resultStream); Assert.Equal(5800, model.gruppeid); Assert.Equal("Ærlige Øksne Åsheim", model.Skattyterinforgrp5801.Kontaktgrp5803.KontaktpersonNavndatadef2.value); }
public override async Task RunDataCreation(Instance instance, object data) { if (data is App.IntegrationTests.Mocks.Apps.tdd.endring_av_navn.Skjema) { Skjema skjema = (Skjema)data; skjema.Begrunnelsegrp9317 = new Begrunnelsegrp9317(); skjema.Begrunnelsegrp9317.BegrunnelseForNyttNavngrp9318 = new BegrunnelseForNyttNavngrp9318(); skjema.Begrunnelsegrp9317.BegrunnelseForNyttNavngrp9318.PersonFornavnAnnetBegrunnelsedatadef34948 = new PersonFornavnAnnetBegrunnelsedatadef34948() { value = "Fordi det er en enhetstest" }; } await Task.CompletedTask; }
public async Task ValidateData(object data, ModelStateDictionary validationResults) { if (data.GetType() == typeof(Skjema)) { Skjema model = (Skjema)data; string middleName = model?.NyttNavngrp9313?.NyttNavngrp9314?.PersonMellomnavnNyttdatadef34759?.value; string firstName = model?.NyttNavngrp9313?.NyttNavngrp9314?.PersonFornavnNyttdatadef34758?.value; if (!string.IsNullOrEmpty(middleName) && middleName.Contains("test")) { validationResults.AddModelError("NyttNavn-grp-9313.NyttNavn-grp-9314.PersonMellomnavnNytt-datadef-34759.value", "*WARNING*test er ikke en gyldig verdi"); } if (!string.IsNullOrEmpty(firstName) && firstName.Contains("test")) { validationResults.AddModelError("NyttNavn-grp-9313.NyttNavn-grp-9314.PersonFornavnNytt-datadef-34758.value", "test er ikke en gyldig verdi"); } } await Task.CompletedTask; }
public async Task Instance_Post_WithNæringOgSkattemelding_ValidateOk() { 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); // Get Data from Instance HttpRequestMessage httpRequestMessageGetData = new HttpRequestMessage(HttpMethod.Get, "/tdd/sirius/instances/" + instance.Id + "/data/" + instance.Data[0].Id); HttpResponseMessage responseData = await client.SendAsync(httpRequestMessageGetData); string responseContentData = await responseData.Content.ReadAsStringAsync(); Skjema siriusMainForm = (Skjema)JsonConvert.DeserializeObject(responseContentData, typeof(Skjema)); // Modify the prefilled form. This would need to be replaced with the real sirius form siriusMainForm.Permisjonsopplysningergrp8822 = new Permisjonsopplysningergrp8822(); siriusMainForm.Permisjonsopplysningergrp8822.AnsattEierandel20EllerMerdatadef33294 = new AnsattEierandel20EllerMerdatadef33294() { value = "50" }; XmlSerializer serializer = new XmlSerializer(typeof(Skjema)); using MemoryStream stream = new MemoryStream(); serializer.Serialize(stream, siriusMainForm); stream.Position = 0; StreamContent streamContent = new StreamContent(stream); streamContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/xml"); HttpResponseMessage putresponse = await client.PutAsync("/tdd/sirius/instances/" + instance.Id + "/data/" + instance.Data[0].Id, streamContent); // Add Næringsoppgave.xml string næringsppgave = File.ReadAllText("Data/Files/data-element.xml"); byte[] byteArray = Encoding.UTF8.GetBytes(næringsppgave); MemoryStream næringsoppgavestream = new MemoryStream(byteArray); StreamContent streamContentNæring = new StreamContent(næringsoppgavestream); streamContentNæring.Headers.ContentType = MediaTypeHeaderValue.Parse("text/xml"); streamContentNæring.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse("attachment; filename=data-element.xml"); HttpResponseMessage postresponseNæring = await client.PostAsync("/tdd/sirius/instances/" + instance.Id + "/data/?datatype=næringsoppgave", streamContentNæring); DataElement dataElementNæring = (DataElement)JsonConvert.DeserializeObject(await postresponseNæring.Content.ReadAsStringAsync(), typeof(DataElement)); // Add skattemelding.xml string skattemelding = File.ReadAllText("Data/Files/data-element.xml"); byte[] byteArraySkattemelding = Encoding.UTF8.GetBytes(næringsppgave); MemoryStream skattemeldingstream = new MemoryStream(byteArraySkattemelding); StreamContent streamContentSkattemelding = new StreamContent(skattemeldingstream); streamContent.Headers.ContentType = MediaTypeHeaderValue.Parse("text/xml"); HttpResponseMessage postresponseskattemelding = await client.PostAsync("/tdd/sirius/instances/" + instance.Id + "/data/?datatype=skattemelding", streamContentNæring); DataElement dataElementSkattemelding = (DataElement)JsonConvert.DeserializeObject(await postresponseskattemelding.Content.ReadAsStringAsync(), typeof(DataElement)); // Validate instance string url = "/tdd/sirius/instances/" + instance.Id + "/validate"; HttpResponseMessage responseValidation = await client.GetAsync(url); string responseContentValidation = await responseValidation.Content.ReadAsStringAsync(); List <ValidationIssue> messages = (List <ValidationIssue>)JsonConvert.DeserializeObject(responseContentValidation, typeof(List <ValidationIssue>)); Assert.Empty(messages); TestDataUtil.DeleteInstanceAndData("tdd", "sirius", 1337, new Guid(instance.Id.Split('/')[1])); }
public async Task Instance_Post_WithNæringOgSkattemelding_ValidateOkThenNext() { // Gets JWT token. In production this would be given from authentication component when exchanging a ID porten token. string token = PrincipalUtil.GetToken(1337); // Setup client and calls Instance controller on the App that instansiates a new instances of the app 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); // Get Data from the main form HttpRequestMessage httpRequestMessageGetData = new HttpRequestMessage(HttpMethod.Get, "/tdd/sirius/instances/" + instance.Id + "/data/" + instance.Data[0].Id); HttpResponseMessage responseData = await client.SendAsync(httpRequestMessageGetData); string responseContentData = await responseData.Content.ReadAsStringAsync(); Skjema siriusMainForm = (Skjema)JsonConvert.DeserializeObject(responseContentData, typeof(Skjema)); // Modify the prefilled form. This would need to be replaced with the real sirius form siriusMainForm.Permisjonsopplysningergrp8822 = new Permisjonsopplysningergrp8822(); siriusMainForm.Permisjonsopplysningergrp8822.AnsattEierandel20EllerMerdatadef33294 = new AnsattEierandel20EllerMerdatadef33294() { value = "50" }; XmlSerializer serializer = new XmlSerializer(typeof(Skjema)); using MemoryStream stream = new MemoryStream(); serializer.Serialize(stream, siriusMainForm); stream.Position = 0; StreamContent streamContent = new StreamContent(stream); streamContent.Headers.ContentType = MediaTypeHeaderValue.Parse("text/xml"); streamContent.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse("attachment; filename=data-element.xml"); HttpResponseMessage putresponse = await client.PutAsync("/tdd/sirius/instances/" + instance.Id + "/data/" + instance.Data[0].Id, streamContent); // Add Næringsoppgave.xml string næringsppgave = File.ReadAllText("Data/Files/data-element.xml"); byte[] byteArray = Encoding.UTF8.GetBytes(næringsppgave); MemoryStream næringsoppgavestream = new MemoryStream(byteArray); StreamContent streamContentNæring = new StreamContent(næringsoppgavestream); streamContentNæring.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse("attachment; filename=data-element.xml"); streamContentNæring.Headers.ContentType = MediaTypeHeaderValue.Parse("text/xml"); HttpResponseMessage postresponseNæring = await client.PostAsync("/tdd/sirius/instances/" + instance.Id + "/data/?datatype=næringsoppgave", streamContentNæring); DataElement dataElementNæring = (DataElement)JsonConvert.DeserializeObject(await postresponseNæring.Content.ReadAsStringAsync(), typeof(DataElement)); // Add skattemelding.xml string skattemelding = File.ReadAllText("Data/Files/data-element.xml"); byte[] byteArraySkattemelding = Encoding.UTF8.GetBytes(skattemelding); MemoryStream skattemeldingstream = new MemoryStream(byteArraySkattemelding); HttpContent streamContentSkattemelding = new StreamContent(skattemeldingstream); streamContent.Headers.ContentType = MediaTypeHeaderValue.Parse("text/xml"); streamContent.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse("attachment; filename=data-element.xml"); HttpResponseMessage postresponseskattemelding = await client.PostAsync("/tdd/sirius/instances/" + instance.Id + "/data/?datatype=skattemelding", streamContentNæring); DataElement dataElementSkattemelding = (DataElement)JsonConvert.DeserializeObject(await postresponseskattemelding.Content.ReadAsStringAsync(), typeof(DataElement)); // Validate instance. This validates that main form has valid data and required data string url = "/tdd/sirius/instances/" + instance.Id + "/validate"; HttpResponseMessage responseValidation = await client.GetAsync(url); string responseContentValidation = await responseValidation.Content.ReadAsStringAsync(); List <ValidationIssue> messages = (List <ValidationIssue>)JsonConvert.DeserializeObject(responseContentValidation, typeof(List <ValidationIssue>)); Assert.Empty(messages); // Handle first next go from data to confirmation HttpRequestMessage httpRequestMessageFirstNext = new HttpRequestMessage(HttpMethod.Put, "/tdd/sirius/instances/" + instance.Id + "/process/next"); HttpResponseMessage responseFirstNext = await client.SendAsync(httpRequestMessageFirstNext); string responseContentFirstNext = await responseFirstNext.Content.ReadAsStringAsync(); ProcessState stateAfterFirstNext = (ProcessState)JsonConvert.DeserializeObject(responseContentFirstNext, typeof(ProcessState)); Assert.Equal("Task_2", stateAfterFirstNext.CurrentTask.ElementId); // Validate instance in Task_2. This validates that PDF for nærings is in place HttpResponseMessage responseValidationTask2 = await client.GetAsync(url); string responseContentValidationTask2 = await responseValidationTask2.Content.ReadAsStringAsync(); List <ValidationIssue> messagesTask2 = (List <ValidationIssue>)JsonConvert.DeserializeObject(responseContentValidationTask2, typeof(List <ValidationIssue>)); Assert.Empty(messagesTask2); // Move process from Task_2 (Confirmation) to Task_3 (Feedback). HttpRequestMessage httpRequestMessageSecondNext = new HttpRequestMessage(HttpMethod.Put, "/tdd/sirius/instances/" + instance.Id + "/process/next"); HttpResponseMessage responseSecondNext = await client.SendAsync(httpRequestMessageSecondNext); string responseContentSecondNext = await responseSecondNext.Content.ReadAsStringAsync(); ProcessState stateAfterSecondNext = (ProcessState)JsonConvert.DeserializeObject(responseContentSecondNext, typeof(ProcessState)); Assert.Equal("Task_3", stateAfterSecondNext.CurrentTask.ElementId); // Delete all data created TestDataUtil.DeleteInstanceAndData("tdd", "sirius", 1337, new Guid(instance.Id.Split('/')[1])); }
public static void Initialize(IApplicationBuilder app) { using (var serviceScope = app.ApplicationServices.CreateScope()) { var context = serviceScope.ServiceProvider.GetService <FAQContext>(); if (context.faqs.Count() == 0) { var faq1 = new FAQ { spørsmål = "Hvor lang tid tar Oslo-Bergen?", svar = "Ca 5 timer", like = 8, dislike = 2 }; var faq2 = new FAQ { spørsmål = "Kan dere lage en stasjon fra Lommedalen til Kolsås?", svar = "Vi vurderer kontinuerlig nye ruter, hvis vi får over 10 likes på denne posten vil vi se at kundegrunnlaget er sterkt nok!", like = 33, dislike = 4 }; var faq3 = new FAQ { spørsmål = "Hvordan kan man få refundert en billett?", svar = "Alle kjøp er endelige og man kan ikke få refundert billetter!", like = 5, dislike = 113 }; var faq4 = new FAQ { spørsmål = "Hei, kunne dere senket prisene i Corona tiden?", svar = "Beklager, vi har ikke klart å frigjøre noen middler.", like = 10, dislike = 9 }; var faq5 = new FAQ { spørsmål = "Må man bruke belte i bussen?", svar = "For egen og andres sikkerhet, er det påbudt å bruke sikkerhetsbelte ombord på bussen!", like = 50, dislike = 5 }; var faq6 = new FAQ { spørsmål = "Finnes det barneseter på bussen?", svar = "Bussene er utstyrt med ett barnesete.", like = 23, dislike = 8 }; var faq7 = new FAQ { spørsmål = "Får honnør rabatt?", svar = "Ja, dette gis til alle over 67 år.", like = 39, dislike = 5 }; var faq8 = new FAQ { spørsmål = "Får studenter rabatt?", svar = "Alle studenter under 30 år og som kan vise gyldig studentbevis får rabatt.", like = 23, dislike = 3 }; var faq9 = new FAQ { spørsmål = "Får ledsagere rabatt?", svar = "Ledsagere som følger døvblinde reiser gratis.", like = 12, dislike = 1 }; var aktueltListe = new List <FAQ>(); aktueltListe.Add(faq4); aktueltListe.Add(faq2); var betalingListe = new List <FAQ>(); betalingListe.Add(faq3); var ruteinfoListe = new List <FAQ>(); ruteinfoListe.Add(faq1); var sikkerhetListe = new List <FAQ>(); sikkerhetListe.Add(faq5); sikkerhetListe.Add(faq6); var rabatterListe = new List <FAQ>(); rabatterListe.Add(faq7); rabatterListe.Add(faq8); rabatterListe.Add(faq9); var kategori1 = new Kategori { id = 1, kategori = "Aktuelt nå", faqs = aktueltListe }; var kategori2 = new Kategori { id = 2, kategori = "Betaling", faqs = betalingListe }; var kategori3 = new Kategori { id = 3, kategori = "Ruteinformasjon", faqs = ruteinfoListe }; var kategori4 = new Kategori { id = 4, kategori = "Sikkerhet", faqs = sikkerhetListe }; var kategori5 = new Kategori { id = 5, kategori = "Rabatter", faqs = rabatterListe }; context.kategorier.Add(kategori1); context.kategorier.Add(kategori2); context.kategorier.Add(kategori3); context.kategorier.Add(kategori4); context.kategorier.Add(kategori5); context.SaveChanges(); } if (context.skjemaer.Count() == 0) { var skjema1 = new Skjema { id = 1, navn = "Nordman", mail = "*****@*****.**", spørsmål = "Hei, kunne dere senket prisene i Corona tiden?" }; var skjema2 = new Skjema { id = 2, navn = "Ola", mail = "*****@*****.**", spørsmål = "Hei, kunne dere satt opp avganger mellom Oslo og Drammen i rushen? Må stå i bussen hver dag!" }; context.skjemaer.Add(skjema1); context.skjemaer.Add(skjema2); context.SaveChanges(); } } }
/// <summary> /// Method to format PDF dynamic /// </summary> /// <example> /// if (data.GetType() == typeof(Skjema) /// { /// // need to create object if not there /// layoutSettings.Components.ExcludeFromPdf.Add("a23234234"); /// } /// </example> /// <param name="layoutSettings">the layoutsettings</param> /// <param name="data">data object</param> public async Task <LayoutSettings> FormatPdf(LayoutSettings layoutSettings, object data) { if (data is Skjema) { Skjema skjema = (Skjema)data; if (skjema.Radioknapp == "1") { layoutSettings.Components.ExcludeFromPdf.AddRange(new List <string>() { "reasonParents", "reasonSSN", "reasonCohabitant1", "reasonCohabitant2", "reasonFarm1", "reasonFarm2", "reasonFarm3", "reasonFarm4", "reasonFarm5", "reasonNewName", "reasonOthers" }); } if (skjema.Radioknapp == "3") { layoutSettings.Components.ExcludeFromPdf.AddRange(new List <string>() { "reasonRelationship", "reasonCohabitant1", "reasonCohabitant2", "reasonFarm1", "reasonFarm2", "reasonFarm3", "reasonFarm4", "reasonFarm5", "reasonNewName", "reasonOthers" }); } if (skjema.Radioknapp == "5") { layoutSettings.Components.ExcludeFromPdf.AddRange(new List <string>() { "reasonRelationship", "reasonParents", "reasonSSN", "reasonFarm1", "reasonFarm2", "reasonFarm3", "reasonFarm4", "reasonFarm5", "reasonNewName", "reasonOthers" }); } if (skjema.Radioknapp == "7") { layoutSettings.Components.ExcludeFromPdf.AddRange(new List <string>() { "reasonRelationship", "reasonParents", "reasonSSN", "reasonCohabitant1", "reasonCohabitant2", "reasonNewName", "reasonOthers" }); } if (skjema.Radioknapp == "8") { layoutSettings.Components.ExcludeFromPdf.AddRange(new List <string>() { "reasonRelationship", "reasonParents", "reasonSSN", "reasonCohabitant1", "reasonCohabitant2", "reasonFarm1", "reasonFarm2", "reasonFarm3", "reasonFarm4", "reasonFarm5", "reasonOthers" }); } if (skjema.Radioknapp == "9") { layoutSettings.Components.ExcludeFromPdf.AddRange(new List <string>() { "reasonRelationship", "reasonParents", "reasonSSN", "reasonCohabitant1", "reasonCohabitant2", "reasonFarm1", "reasonFarm2", "reasonFarm3", "reasonFarm4", "reasonFarm5", "reasonNewName" }); } } return(await Task.FromResult(layoutSettings)); }
public async Task ValidateInstance_Validation_ReturnsNoError() { // Arrange Application application = new Application { Id = $"{org}/{app}", ElementTypes = new List <ElementType> { new ElementType { Id = "default", AppLogic = true, AllowedContentType = new List <string> { "application/xml" }, Task = "FormFilling_1" } } }; Instance getInstance = new Instance { Id = $"{instanceOwnerId}/{instanceGuid}", InstanceOwnerId = $"{instanceOwnerId}", AppId = $"{org}/{app}", Org = org, Process = new ProcessState { CurrentTask = new ProcessElementInfo { AltinnTaskType = "FormFilling", ElementId = "FormFilling_1" } }, Data = new List <DataElement> { new DataElement { Id = $"{dataGuid}", ElementType = "default", StorageUrl = "www.storageuri.com", ContentType = "application/xml" } } }; Skjema model = new Skjema(); FileStream dataElement = File.OpenRead("Runtime/data/data-element.xml"); Mock <HttpRequest> request = MockRequest(); request.SetupGet(x => x.Body).Returns(dataElement); var context = new Mock <HttpContext>(); context.SetupGet(x => x.Request).Returns(request.Object); context.SetupGet(x => x.User).Returns(MockUser().Object); Mock <IApplication> appServiceMock = new Mock <IApplication>(); appServiceMock .Setup(i => i.GetApplication(It.IsAny <string>(), It.IsAny <string>())) .Returns(Task.FromResult(application)); Mock <IInstance> instanceServiceMock = new Mock <IInstance>(); instanceServiceMock .Setup(i => i.GetInstance(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.Is <Guid>(g => g.Equals(instanceGuid)))) .Returns(Task.FromResult(getInstance)); Mock <IData> dataServiceMock = new Mock <IData>(); dataServiceMock .Setup(d => d.GetFormData(It.IsAny <Guid>(), It.IsAny <Type>(), org, app, instanceOwnerId, It.IsAny <Guid>())) .Returns(model); ValidateController target = NewValidateController(context, instanceServiceMock, dataServiceMock, appServiceMock); // Act IActionResult result = await target.ValidateInstance(org, app, instanceOwnerId, instanceGuid); OkObjectResult actual = result as OkObjectResult; // Arrange Assert.NotNull(actual); List <ValidationIssue> validationIssues = actual.Value as List <ValidationIssue>; Assert.NotNull(validationIssues); Assert.Empty(validationIssues); }
public void Get_TC01_FormData() { /* SETUP TEST DATA */ Application application = new Application() { Id = $"{org}/{app}", ElementTypes = new List<ElementType>() { new ElementType() { Id = "default", AppLogic = true } } }; Instance instance = new Instance() { Id = $"{instanceOwnerId}/{instanceGuid}", InstanceOwnerId = $"{instanceOwnerId}", AppId = $"{org}/{app}", Org = org, Data = new List<DataElement>() { new DataElement() { Id = $"{dataGuid}", ElementType = "default", ContentType = "application/xml", } } }; XmlSerializer serializer = new XmlSerializer(typeof(Skjema)); object skjema = serializer.Deserialize(File.OpenRead("Runtime/data/data-element.xml")); /* SETUP MOCK SERVICES */ Mock<HttpRequest> request = MockRequest(); var context = new Mock<HttpContext>(); context.SetupGet(x => x.Request).Returns(request.Object); context.SetupGet(x => x.User).Returns(MockUser().Object); Mock<IApplication> appServiceMock = new Mock<IApplication>(); appServiceMock .Setup(i => i.GetApplication(It.IsAny<string>(), It.IsAny<string>())) .Returns(Task.FromResult(application)); Mock<IInstance> instanceServiceMock = new Mock<IInstance>(); instanceServiceMock .Setup(i => i.GetInstance(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<Guid>())) .Returns(Task.FromResult(instance)); Mock<IData> dataServiceMock = new Mock<IData>(); dataServiceMock .Setup(d => d.GetFormData(instanceGuid, It.IsAny<Type>(), org, app, instanceOwnerId, dataGuid)) .Returns(skjema); /* TEST */ DataController dataController = NewDataController(context, instanceServiceMock, dataServiceMock, appServiceMock); ActionResult result = dataController.Get(org, app, instanceOwnerId, instanceGuid, dataGuid).Result; Assert.IsType<OkObjectResult>(result); OkObjectResult okresult = result as OkObjectResult; Skjema model = (Skjema)okresult.Value; Assert.Equal(5800, model.gruppeid); Assert.Equal("Ærlige Øksne Åsheim", model.Skattyterinforgrp5801.Kontaktgrp5803.KontaktpersonNavndatadef2.value); }