public async Task Cannot_Delete_Advice_That_Does_Not_Exist() { //Arrange //Act using var deleteResult = await AdviceHelper.DeleteAdviceAsync(0); //Assert Assert.Equal(HttpStatusCode.NotFound, deleteResult.StatusCode); }
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); }
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); }
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); }
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); }