public async Task AddLocalAuthorityWithValidAuthorityMeetsVerification() { // arrange const string pKey = "not_required"; var sut = MakeSUT(); var touchpoint = "any old touchpoint"; var ladcode = "E000606060"; var laResourcePath = new Uri("any/old/la/resource/path", UriKind.Relative); var la = new IncomingLocalAuthority { TouchpointID = touchpoint, LADCode = ladcode }; GetMock(sut.StoragePaths) .Setup(x => x.GetLocalAuthorityResourcePathFor(ladcode)) .Returns(laResourcePath); GetMock(sut.StoragePaths) .SetupGet(x => x.LocalAuthorityCollection) .Returns(laResourcePath); GetMock(sut.DocumentStore) .Setup(x => x.DocumentExists <LocalAuthority>(laResourcePath, pKey)) .Returns(Task.FromResult(false)); GetMock(sut.DocumentStore) .Setup(x => x.AddDocument(la, It.IsAny <Uri>())) .Returns(Task.FromResult(la)); // act var result = await sut.Add(la); // assert GetMock(sut.StoragePaths).VerifyAll(); GetMock(sut.DocumentStore).VerifyAll(); Assert.Equal(la, result); }
public async Task AddLocalAuthorityWithNoLADCodeThrows() { // arrange var sut = MakeSUT(); var touchpoint = "any old touchpoint"; var resourcePath = new Uri("any/old/resource/path", UriKind.Relative); var la = new IncomingLocalAuthority { TouchpointID = touchpoint }; GetMock(sut.DocumentStore) .Setup(x => x.DocumentExists <LocalAuthority>(resourcePath, "not_required")) .Returns(Task.FromResult(true)); // act / assert await Assert.ThrowsAsync <ArgumentNullException>(() => sut.Add(la)); }
public async Task AddLocalAuthorityWithExistingLADCodeThrows() { // arrange var sut = MakeSUT(); var touchpoint = "any old touchpoint"; var ladcode = "E000606060"; var laResourcePath = new Uri("any/old/la/resource/path", UriKind.Relative); var la = new IncomingLocalAuthority { TouchpointID = touchpoint, LADCode = ladcode }; GetMock(sut.StoragePaths) .Setup(x => x.GetLocalAuthorityResourcePathFor(ladcode)) .Returns(laResourcePath); GetMock(sut.DocumentStore) .Setup(x => x.DocumentExists <LocalAuthority>(laResourcePath, "not_required")) .Returns(Task.FromResult(true)); // act / assert await Assert.ThrowsAsync <ConflictingResourceException>(() => sut.Add(la)); }
/// <summary> /// add... /// </summary> /// <param name="theCandidate">the candidate (authority)</param> /// <returns>the newly added local authority</returns> public async Task <ILocalAuthority> Add(IncomingLocalAuthority theCandidate) { It.IsNull(theCandidate) .AsGuard <ArgumentNullException>(nameof(theCandidate)); var theTouchpoint = theCandidate.TouchpointID; It.IsEmpty(theTouchpoint) .AsGuard <ArgumentNullException>(nameof(theTouchpoint)); var theAdminDistrict = theCandidate.LADCode; It.IsNull(theAdminDistrict) .AsGuard <ArgumentNullException>(nameof(theAdminDistrict)); var usingAuthorityPath = StoragePaths.GetLocalAuthorityResourcePathFor(theAdminDistrict); (await DocumentStore.DocumentExists <LocalAuthority>(usingAuthorityPath, _partitionKey)) .AsGuard <ConflictingResourceException>(); return(await DocumentStore.AddDocument(theCandidate, StoragePaths.LocalAuthorityCollection)); }
public async Task CreateDocumentAsyncMeetsExpectation() { // arrange const string keyValue = "0000123"; var sut = MakeSUT(); var document = new IncomingLocalAuthority { LADCode = keyValue }; var collectionUri = new Uri("dbs/areas/colls/routing", UriKind.Relative); var documentUri = new Uri($"dbs/areas/colls/routing/docs/{keyValue}", UriKind.Relative); GetMock(sut.Client) .Setup(x => x.CreateDocumentAsync(collectionUri, document, It.IsAny <RequestOptions>(), false, default)) .Returns(Task.FromResult(new ResourceResponse <Document>(new Document()))); GetMock(sut.Client) .Setup(x => x.ReadDocumentAsync <IncomingLocalAuthority>(documentUri, It.IsAny <RequestOptions>(), default)) .Returns(Task.FromResult(new DocumentResponse <IncomingLocalAuthority>(document))); // act var result = await sut.CreateDocumentAsync(collectionUri, document); // assert Assert.IsAssignableFrom <ILocalAuthority>(result); }