Exemple #1
0
        public async Task Delete_Contract_Removes_Associated_Advices()
        {
            // Arrange
            const int organizationId = TestEnvironment.DefaultOrganizationId;
            var       contract       = await ItContractHelper.CreateContract(A <string>(), OrganizationId);

            var advice = new Core.DomainModel.Advice.Advice
            {
                Id         = A <int>(),
                AlarmDate  = DateTime.Now,
                StopDate   = DateTime.Now.AddDays(365),
                Scheduling = Scheduling.Quarter,
                Subject    = "Can_Delete_Contract_Advices",
                RelationId = contract.Id,
                Type       = RelatedEntityType.itProject
            };

            using var createResponse = await AdviceHelper.PostAdviceAsync(advice, organizationId);

            Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

            // Act
            using var deleteResponse = await ItContractHelper.SendDeleteContractRequestAsync(contract.Id);

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

            // Assert
            using var advicesResponse = AdviceHelper.GetContractAdvicesAsync(contract.Id);
            var deletedContractAdvices = await advicesResponse.Result.ReadOdataListResponseBodyAsAsync <Core.DomainModel.Advice.Advice>();

            Assert.True(deletedContractAdvices.Count == 0);
        }
Exemple #2
0
        public async Task Can_Add_Repeatable_Advice_With_StartDate_Today()
        {
            //Arrange
            var recipient    = CreateDefaultEmailRecipient(CreateWellformedEmail());
            var createAdvice = CreateDefaultAdvice(Scheduling.Day, AdviceType.Repeat, recipient);

            //Act
            using var result = await AdviceHelper.PostAdviceAsync(createAdvice, OrganizationId);

            //Assert
            Assert.Equal(HttpStatusCode.Created, result.StatusCode);
        }
Exemple #3
0
        public async Task Cannot_Add_Advice_When_Emails_Are_Malformed()
        {
            //Arrange
            var recipient    = CreateDefaultEmailRecipient(A <string>()); // Malformed email
            var createAdvice = CreateDefaultAdvice(Scheduling.Day, A <AdviceType>(), recipient);

            //Act
            using var result = await AdviceHelper.PostAdviceAsync(createAdvice, OrganizationId);

            //Assert
            Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);
        }
Exemple #4
0
        public async Task Cannot_Add_Repeatable_Advice_With_StopDate_Before_StartDate()
        {
            //Arrange
            var recipient    = CreateDefaultEmailRecipient(CreateWellformedEmail());
            var createAdvice = CreateDefaultAdvice(Scheduling.Day, AdviceType.Repeat, recipient);

            createAdvice.StopDate = DateTime.Now.AddDays(-1);

            //Act
            using var result = await AdviceHelper.PostAdviceAsync(createAdvice, OrganizationId);

            //Assert
            Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);
        }
Exemple #5
0
        public async Task Cannot_Add_Advice_If_No_RelationId_Defined()
        {
            //Arrange
            var recipient = CreateDefaultEmailRecipient(CreateWellformedEmail());

            var createAdvice = CreateDefaultAdvice(Scheduling.Day, A <AdviceType>(), recipient);

            createAdvice.RelationId = null;

            //Act
            using var result = await AdviceHelper.PostAdviceAsync(createAdvice, OrganizationId);

            //Assert
            Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);
        }
Exemple #6
0
        public async Task Cannot_Delete_Active_Advice()
        {
            //Arrange
            var recipient    = CreateDefaultEmailRecipient(CreateWellformedEmail());
            var createAdvice = CreateDefaultAdvice(Scheduling.Day, AdviceType.Repeat, recipient);

            using var createResult = await AdviceHelper.PostAdviceAsync(createAdvice, OrganizationId);

            Assert.Equal(HttpStatusCode.Created, createResult.StatusCode);
            var createdAdvice = await createResult.ReadResponseBodyAsAsync <Core.DomainModel.Advice.Advice>();

            //Act
            using var deleteResult = await AdviceHelper.DeleteAdviceAsync(createdAdvice.Id);

            //Assert
            Assert.Equal(HttpStatusCode.BadRequest, deleteResult.StatusCode);
        }
Exemple #7
0
        public async Task Can_Add_Advice_With_Multiple_Email_Receivers()
        {
            //Arrange
            var recipient1 = CreateDefaultEmailRecipient(CreateWellformedEmail());
            var recipient2 = CreateDefaultEmailRecipient(CreateWellformedEmail());
            var recipient3 = CreateDefaultEmailRecipient(CreateWellformedEmail());

            var createAdvice = CreateDefaultAdvice(Scheduling.Day, A <AdviceType>(), recipient1);

            createAdvice.Reciepients.Add(recipient2);
            createAdvice.Reciepients.Add(recipient3);

            //Act
            using var result = await AdviceHelper.PostAdviceAsync(createAdvice, OrganizationId);

            //Assert
            Assert.Equal(HttpStatusCode.Created, result.StatusCode);
        }
Exemple #8
0
        public async Task Cannot_Delete_Advice_That_Has_Been_Sent()
        {
            //Arrange
            var recipient    = CreateDefaultEmailRecipient(CreateWellformedEmail());
            var createAdvice = CreateDefaultAdvice(Scheduling.Day, AdviceType.Immediate, recipient);

            using var createResult = await AdviceHelper.PostAdviceAsync(createAdvice, OrganizationId);

            Assert.Equal(HttpStatusCode.Created, createResult.StatusCode);
            var createdAdvice = await createResult.ReadResponseBodyAsAsync <Core.DomainModel.Advice.Advice>();

            //Wait for the advice to have been sent
            await WaitForAsync(() => Task.FromResult(DatabaseAccess.MapFromEntitySet <Core.DomainModel.Advice.Advice, bool>(advices => advices.AsQueryable().ById(createdAdvice.Id).AdviceSent.Any())), TimeSpan.FromSeconds(10));


            //Act
            using var deleteResult = await AdviceHelper.DeleteAdviceAsync(createdAdvice.Id);

            //Assert
            Assert.Equal(HttpStatusCode.BadRequest, deleteResult.StatusCode);
        }
Exemple #9
0
        public async Task Cannot_Delete_Inactive_Advice_That_Has_Not_Been_Sent_If_No_Rights()
        {
            //Arrange
            var recipient = CreateDefaultEmailRecipient(CreateWellformedEmail());
            var advice    = CreateDefaultAdvice(Scheduling.Day, AdviceType.Repeat, recipient);

            using var createResult = await AdviceHelper.PostAdviceAsync(advice, OrganizationId);

            Assert.Equal(HttpStatusCode.Created, createResult.StatusCode);
            var createdAdvice = await createResult.ReadResponseBodyAsAsync <Core.DomainModel.Advice.Advice>();

            using var deactivateResult = await AdviceHelper.DeactivateAdviceAsync(createdAdvice.Id);

            Assert.Equal(HttpStatusCode.NoContent, deactivateResult.StatusCode);

            var regularUserCookie = await HttpApi.GetCookieAsync(OrganizationRole.User);

            //Act
            using var deleteResult = await AdviceHelper.DeleteAdviceAsync(createdAdvice.Id, regularUserCookie);

            //Assert
            Assert.Equal(HttpStatusCode.Forbidden, deleteResult.StatusCode);
        }
Exemple #10
0
        public async Task Can_Delete_Inactive_Advice_That_Has_Not_Been_Sent()
        {
            //Arrange
            var recipient = CreateDefaultEmailRecipient(CreateWellformedEmail());
            var advice    = CreateDefaultAdvice(Scheduling.Day, AdviceType.Repeat, recipient);

            advice.AlarmDate = DateTime.Now.AddDays(2);
            advice.StopDate  = DateTime.Now.AddDays(3);

            using var createResult = await AdviceHelper.PostAdviceAsync(advice, OrganizationId);

            Assert.Equal(HttpStatusCode.Created, createResult.StatusCode);
            var createdAdvice = await createResult.ReadResponseBodyAsAsync <Core.DomainModel.Advice.Advice>();

            using var deactivateResult = await AdviceHelper.DeactivateAdviceAsync(createdAdvice.Id);

            Assert.Equal(HttpStatusCode.NoContent, deactivateResult.StatusCode);

            //Act
            using var deleteResult = await AdviceHelper.DeleteAdviceAsync(createdAdvice.Id);

            //Assert
            Assert.Equal(HttpStatusCode.NoContent, deleteResult.StatusCode);
        }
Exemple #11
0
        private static async Task AssertAdviceCreationReturns(Core.DomainModel.Advice.Advice advice, Cookie readOnlyUserCookie, HttpStatusCode expectedResult)
        {
            using var createResultBeforeRoleAssignment = await AdviceHelper.PostAdviceAsync(advice, OrganizationId, readOnlyUserCookie);

            Assert.Equal(expectedResult, createResultBeforeRoleAssignment.StatusCode);
        }