Esempio n. 1
0
        public async Task Changing_Exposing_System_To_Same_As_Existing_Does_Nothing()
        {
            //Arrange
            var input = await PrepareFullRelationAsync(false, false, true);

            var toUsage = await ItSystemHelper.GetItSystemUsage(input.ToUsageId);

            //Act
            using (var response = await SystemRelationHelper.SendPostRelationRequestAsync(input))
                using (var changeExposingSystem = await InterfaceExhibitHelper.SendCreateExhibitRequest(toUsage.ItSystemId, input.InterfaceId.GetValueOrDefault()))
                {
                    //Assert
                    Assert.Equal(HttpStatusCode.Created, response.StatusCode);
                    Assert.Equal(HttpStatusCode.Created, changeExposingSystem.StatusCode);
                    var relation = await response.ReadResponseBodyAsKitosApiResponseAsync <SystemRelationDTO>();

                    Assert.NotNull(relation.Interface);
                    using (var getAfterDeleteResponse = await SystemRelationHelper.SendGetRelationRequestAsync(input.FromUsageId, relation.Id))
                    {
                        Assert.Equal(HttpStatusCode.OK, getAfterDeleteResponse.StatusCode);
                        var relationAfterChange = await getAfterDeleteResponse.ReadResponseBodyAsKitosApiResponseAsync <SystemRelationDTO>();

                        Assert.NotNull(relationAfterChange.Interface); //interface should not have been cleared since the same exhibitor was provided as the existing --> no change
                    }
                }
        }
Esempio n. 2
0
        public async Task Deleting_Interface_Clears_InterfaceField_In_All_Relations_To_Old_Exposing_System()
        {
            //Arrange
            var input = await PrepareFullRelationAsync(false, false, true);

            //Act
            using (var response = await SystemRelationHelper.SendPostRelationRequestAsync(input))
            {
                Assert.Equal(HttpStatusCode.Created, response.StatusCode);
                var relation = await response.ReadResponseBodyAsKitosApiResponseAsync <SystemRelationDTO>();

                Assert.NotNull(relation.Interface);

                using (var removeExhibitResponse = await InterfaceExhibitHelper.SendRemoveExhibitRequest(input.InterfaceId.GetValueOrDefault())) //Must remove exposition to allow deletion
                    using (var deleteInterfaceResponse = await InterfaceHelper.SendDeleteInterfaceRequestAsync(input.InterfaceId.GetValueOrDefault()))
                        using (var getAfterDeleteResponse = await SystemRelationHelper.SendGetRelationRequestAsync(input.FromUsageId, relation.Id))
                        {
                            //Assert
                            Assert.Equal(HttpStatusCode.OK, removeExhibitResponse.StatusCode);
                            Assert.Equal(HttpStatusCode.OK, deleteInterfaceResponse.StatusCode);
                            Assert.Equal(HttpStatusCode.OK, getAfterDeleteResponse.StatusCode);
                            var relationAfterChange = await getAfterDeleteResponse.ReadResponseBodyAsKitosApiResponseAsync <SystemRelationDTO>();

                            Assert.Null(relationAfterChange.Interface);
                        }
            }
        }
Esempio n. 3
0
        public async Task Changing_Exposing_System_On_Interface_Clears_InterfaceField_In_All_Relations_To_Old_Exposing_System()
        {
            //Arrange
            var newExhibitor = await ItSystemHelper.CreateItSystemInOrganizationAsync(A <string>(), TestEnvironment.DefaultOrganizationId, AccessModifier.Public);

            var input = await PrepareFullRelationAsync(false, false, true);

            //Act
            using (var response = await SystemRelationHelper.SendPostRelationRequestAsync(input))
                using (var changeExposingSystem = await InterfaceExhibitHelper.SendCreateExhibitRequest(newExhibitor.Id, input.InterfaceId.GetValueOrDefault()))
                {
                    //Assert
                    Assert.Equal(HttpStatusCode.Created, response.StatusCode);
                    Assert.Equal(HttpStatusCode.Created, changeExposingSystem.StatusCode);
                    var relation = await response.ReadResponseBodyAsKitosApiResponseAsync <SystemRelationDTO>();

                    Assert.NotNull(relation.Interface);
                    using (var getAfterDeleteResponse = await SystemRelationHelper.SendGetRelationRequestAsync(input.FromUsageId, relation.Id))
                    {
                        Assert.Equal(HttpStatusCode.OK, getAfterDeleteResponse.StatusCode);
                        var relationAfterChange = await getAfterDeleteResponse.ReadResponseBodyAsKitosApiResponseAsync <SystemRelationDTO>();

                        Assert.Null(relationAfterChange.Interface);
                    }
                }
        }
Esempio n. 4
0
        public async Task Cannot_Delete_System_With_Interface_Exhibits(OrganizationRole role)
        {
            //Arrange
            var login = await HttpApi.GetCookieAsync(role);

            const int organizationId = TestEnvironment.DefaultOrganizationId;

            var system = await ItSystemHelper.CreateItSystemInOrganizationAsync(A <string>(), organizationId, AccessModifier.Public);

            var itInterfaceDto = InterfaceHelper.CreateInterfaceDto(
                A <string>(),
                A <string>(),
                organizationId,
                AccessModifier.Public);
            var itInterface = await InterfaceHelper.CreateInterface(itInterfaceDto);

            await InterfaceExhibitHelper.CreateExhibit(system.Id, itInterface.Id);

            //Act
            using (var result = await ItSystemHelper.DeleteItSystemAsync(system.Id, organizationId, login))
            {
                //Assert
                await AssertCorrectConflictResponseAsync(SystemDeleteConflict.HasInterfaceExhibits, result, system.Id);
            }
        }
Esempio n. 5
0
        public async Task Cannot_Set_Exposing_System(OrganizationRole role)
        {
            //Arrange
            var login = await HttpApi.GetCookieAsync(role);

            const int organizationId = TestEnvironment.DefaultOrganizationId;
            var       interfaceDto   = await InterfaceHelper.CreateInterface(InterfaceHelper.CreateInterfaceDto(A <string>(), A <string>(), organizationId, AccessModifier.Public));

            var system = await ItSystemHelper.CreateItSystemInOrganizationAsync(A <string>(), organizationId, AccessModifier.Public);

            //Act - perform the action with the actual role
            using (var result = await InterfaceExhibitHelper.SendCreateExhibitRequest(system.Id, interfaceDto.Id, login))
            {
                //Assert
                Assert.Equal(HttpStatusCode.Forbidden, result.StatusCode);
            }
        }
Esempio n. 6
0
        public async Task BelongsTo_Is_Same_As_Exhibit_System()
        {
            //Arrange
            const int organizationId = TestEnvironment.DefaultOrganizationId;
            var       interfaceDto   = await InterfaceHelper.CreateInterface(InterfaceHelper.CreateInterfaceDto(A <string>(), A <string>(), organizationId, AccessModifier.Public));

            var system = await ItSystemHelper.CreateItSystemInOrganizationAsync(A <string>(), organizationId, AccessModifier.Public);

            //Act - perform the action with the actual role
            await InterfaceExhibitHelper.CreateExhibit(system.Id, interfaceDto.Id);

            //Assert
            var interfaceResult = await InterfaceHelper.GetInterfaceById(interfaceDto.Id);

            var systemResult = await ItSystemHelper.GetSystemAsync(system.Id);

            Assert.Equal(systemResult.BelongsToName, interfaceResult.BelongsToName);
        }
Esempio n. 7
0
        private async Task <CreateSystemRelationDTO> PrepareFullRelationAsync(bool withContract, bool withFrequency, bool withInterface)
        {
            var system1 = await ItSystemHelper.CreateItSystemInOrganizationAsync(CreateName(), OrganizationId, AccessModifier.Public);

            var system2 = await ItSystemHelper.CreateItSystemInOrganizationAsync(CreateName(), OrganizationId, AccessModifier.Public);

            var usage1 = await ItSystemHelper.TakeIntoUseAsync(system1.Id, OrganizationId);

            var usage2 = await ItSystemHelper.TakeIntoUseAsync(system2.Id, OrganizationId);

            var targetInterface = Maybe <ItInterfaceDTO> .None;

            if (withInterface)
            {
                targetInterface = await InterfaceHelper.CreateInterface(InterfaceHelper.CreateInterfaceDto(CreateName(), CreateName(), OrganizationId, AccessModifier.Public));

                await InterfaceExhibitHelper.CreateExhibit(system2.Id, targetInterface.Value.Id);
            }

            var contract = withContract ? await ItContractHelper.CreateContract(CreateName(), OrganizationId) : Maybe <ItContractDTO> .None;

            var targetFrequencyTypeId = withFrequency ? DatabaseAccess.MapFromEntitySet <RelationFrequencyType, int>(repo =>
            {
                var first = repo
                            .AsQueryable()
                            .First(x => x.IsEnabled);
                return(first.Id);
            }) : default(int?);

            var input = new CreateSystemRelationDTO
            {
                FromUsageId     = usage1.Id,
                ToUsageId       = usage2.Id,
                ContractId      = contract.Select <int?>(x => x.Id).GetValueOrDefault(),
                InterfaceId     = targetInterface.Select <int?>(x => x.Id).GetValueOrDefault(),
                Description     = A <string>(),
                Reference       = A <string>(),
                FrequencyTypeId = targetFrequencyTypeId
            };

            return(input);
        }
Esempio n. 8
0
 private static async Task <ItInterfaceExhibitDTO> CreateExhibitAsync(ItInterfaceDTO exposedInterface, ItSystemDTO exposingSystem)
 {
     return(await InterfaceExhibitHelper.CreateExhibit(exposingSystem.Id, exposedInterface.Id));
 }