public async Task AddEvent_RegisterEventWithInstanceOwnerOrganisation_CloudEventInRequestContainOrganisationNumber()
        {
            // Arrange
            Instance instance = new Instance
            {
                AppId         = "ttd/best-app",
                Org           = "ttd",
                InstanceOwner = new InstanceOwner
                {
                    OrganisationNumber = "org",
                    PartyId            = 123.ToString()
                }
            };

            HttpResponseMessage httpResponseMessage = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(Guid.NewGuid().ToString())
            };

            HttpRequestMessage actualRequest = null;

            void SetRequest(HttpRequestMessage request) => actualRequest = request;

            InitializeMocks(httpResponseMessage, SetRequest);

            HttpClient httpClient = new HttpClient(handlerMock.Object);

            EventsAppSI target = new EventsAppSI(
                platformSettingsOptions.Object,
                contextAccessor.Object,
                httpClient,
                accessTokenGeneratorMock.Object,
                appResourcesMock.Object,
                appSettingsOptions.Object,
                generalSettingsOptions.Object);

            // Act
            await target.AddEvent("created", instance);

            // Assert
            Assert.NotNull(actualRequest);
            Assert.Equal(HttpMethod.Post, actualRequest.Method);
            Assert.EndsWith("app", actualRequest.RequestUri.OriginalString);

            string requestContent = await actualRequest.Content.ReadAsStringAsync();

            CloudEvent actualEvent = JsonSerializer.Deserialize <CloudEvent>(requestContent);

            Assert.NotNull(actualEvent);
            Assert.Equal("/party/123", actualEvent.Subject);
            Assert.Equal("/org/org", actualEvent.AlternativeSubject);
            Assert.Contains("ttd.apps.at22.altinn.cloud/ttd/best-app/instances", actualEvent.Source.OriginalString);

            handlerMock.VerifyAll();
        }
        public async Task AddEvent_TheServiceResponseIndicateFailure_ThrowsPlatformHttpException()
        {
            // Arrange
            Instance instance = new Instance
            {
                Org           = "ttd",
                InstanceOwner = new InstanceOwner {
                    OrganisationNumber = "org"
                }
            };

            HttpResponseMessage httpResponseMessage = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.BadRequest,
                Content    = new StringContent(Guid.NewGuid().ToString()),
            };

            HttpRequestMessage actualRequest = null;

            void SetRequest(HttpRequestMessage request) => actualRequest = request;

            InitializeMocks(httpResponseMessage, SetRequest);

            HttpClient httpClient = new HttpClient(handlerMock.Object);

            EventsAppSI target = new EventsAppSI(
                platformSettingsOptions.Object,
                contextAccessor.Object,
                httpClient,
                accessTokenGeneratorMock.Object,
                appResourcesMock.Object,
                appSettingsOptions.Object,
                generalSettingsOptions.Object);

            PlatformHttpException actual = null;

            // Act
            try
            {
                await target.AddEvent("created", instance);
            }
            catch (PlatformHttpException platformHttpException)
            {
                actual = platformHttpException;
            }

            // Assert
            Assert.NotNull(actual);
            Assert.Equal(HttpStatusCode.BadRequest, actual.Response.StatusCode);

            Assert.NotNull(actualRequest);

            handlerMock.VerifyAll();
        }