public async void Delete_SoftDeleteActiveInstance_InstanceIsMarked_EventIsCreated_ReturnsTrue() { // Arrange MessageBoxTestData testData = new MessageBoxTestData(); Instance instance = testData.GetActiveInstance(); Mock <IApplicationRepository> applicationRepository = new Mock <IApplicationRepository>(); Instance storedInstance = null; Mock <IInstanceRepository> instanceRepository = new Mock <IInstanceRepository>(); instanceRepository.Setup(s => s.GetOne(It.IsAny <string>(), It.IsAny <int>())).ReturnsAsync(instance); instanceRepository.Setup(s => s.Update(It.IsAny <Instance>())).Callback <Instance>(p => storedInstance = p).ReturnsAsync((Instance i) => i); InstanceEvent instanceEvent = null; Mock <IInstanceEventRepository> instanceEventRepository = new Mock <IInstanceEventRepository>(); instanceEventRepository.Setup(s => s.InsertInstanceEvent(It.IsAny <InstanceEvent>())).Callback <InstanceEvent>(p => instanceEvent = p) .ReturnsAsync((InstanceEvent r) => r); HttpClient client = GetTestClient(instanceRepository.Object, applicationRepository.Object, instanceEventRepository.Object); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _validToken); // Act HttpResponseMessage response = await client.DeleteAsync($"{BasePath}/sbl/instances/{testData.GetInstanceOwnerPartyId()}/{instance.Id.Split("/")[1]}?hard=false"); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); string content = await response.Content.ReadAsStringAsync(); bool actualResult = JsonConvert.DeserializeObject <bool>(content); Assert.True(actualResult); Assert.True(storedInstance.Status.SoftDeleted.HasValue); Assert.False(storedInstance.Status.HardDeleted.HasValue); Assert.NotNull(instanceEvent); Assert.Equal("Deleted", instanceEvent.EventType); }
public async void Delete_ResponseIsDeny_ReturnsStatusForbidden() { // Arrange MessageBoxTestData testData = new MessageBoxTestData(); Instance instance = testData.GetActiveInstance(); Mock <IApplicationRepository> applicationRepository = new Mock <IApplicationRepository>(); Instance storedInstance = null; Mock <IInstanceRepository> instanceRepository = new Mock <IInstanceRepository>(); instanceRepository.Setup(s => s.GetOne(It.IsAny <string>(), It.IsAny <int>())).ReturnsAsync(instance); instanceRepository.Setup(s => s.Update(It.IsAny <Instance>())).Callback <Instance>(p => storedInstance = p).ReturnsAsync((Instance i) => i); InstanceEvent instanceEvent = null; Mock <IInstanceEventRepository> instanceEventRepository = new Mock <IInstanceEventRepository>(); instanceEventRepository.Setup(s => s.InsertInstanceEvent(It.IsAny <InstanceEvent>())).Callback <InstanceEvent>(p => instanceEvent = p) .ReturnsAsync((InstanceEvent r) => r); HttpClient client = GetTestClient(instanceRepository.Object, applicationRepository.Object, instanceEventRepository.Object); string token = PrincipalUtil.GetToken(-1); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); // Act HttpResponseMessage response = await client.DeleteAsync($"{BasePath}/sbl/instances/{testData.GetInstanceOwnerPartyId()}/{instance.Id.Split("/")[1]}?hard=false"); // Assert Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode); string content = await response.Content.ReadAsStringAsync(); Assert.True(string.IsNullOrEmpty(content)); }