public async Task Upsert_ValidRequestWithBuilding_SavesInCrmAndCaches() { const string testName = "test"; var buildingId = Guid.NewGuid(); var newBuilding = new TeachingEventBuilding() { Id = buildingId }; var newTeachingEvent = new TeachingEvent() { Name = testName, Building = newBuilding }; _mockCrm.Setup(mock => mock.Save(newBuilding)).Verifiable(); _mockCrm.Setup(mock => mock.Save(It.Is <TeachingEvent>(e => e.BuildingId == buildingId))).Verifiable(); _mockStore.Setup(mock => mock.SaveAsync(new TeachingEventBuilding[] { newBuilding })).Verifiable(); _mockStore.Setup(mock => mock.SaveAsync(new TeachingEvent[] { newTeachingEvent })).Verifiable(); var response = await _controller.Upsert(newTeachingEvent); _mockCrm.Verify(); _mockStore.Verify(); var created = response.Should().BeOfType <CreatedAtActionResult>().Subject; var teachingEvent = created.Value.Should().BeAssignableTo <TeachingEvent>().Subject; teachingEvent.Name.Should().Be(testName); teachingEvent.Building.Should().Be(newBuilding); }
private static List <TeachingEventBuilding> MockTeachingEventBuildings() { var building1 = new TeachingEventBuilding() { Id = new Guid("67ffca5c-5adc-4a63-abb7-632c9ecbf283") }; var building2 = new TeachingEventBuilding() { Id = new Guid("194c0926-5f15-434d-88ba-f76c376ac865"), AddressLine1 = "Line 1", AddressPostcode = "KY11 9YU" }; var building3 = new TeachingEventBuilding() { Id = new Guid("6dc656a8-50cc-4802-a62a-47576ddbc493"), AddressLine1 = "Line 1", AddressPostcode = "KY6 2NJ", }; var building4 = new TeachingEventBuilding() { Id = new Guid("adc3e6ce-65a8-4752-abcd-781365982a33"), AddressLine1 = "Line 1", AddressPostcode = "CA4 8LE" }; var building5 = new TeachingEventBuilding() { Id = new Guid("deb12260-84fc-43b5-8682-13aa1015f100"), AddressPostcode = "TE7 9IN" }; return(new List <TeachingEventBuilding> { building1, building2, building3, building4, building5 }); }