public void GetByMapping() { var requester = new Mock <IMessageRequester>(); var service = new MdmEntityService <SourceSystem>("sourcesystem", requester.Object); var entity = new SourceSystem { Details = new SourceSystemDetails { Name = "Gas" }, Identifiers = new MdmIdList { new MdmId { SystemName = "Nexus", Identifier = "1", IsMdmId = true }, new MdmId { SystemName = "Trayport", Identifier = "A" }, new MdmId { SystemName = "Endur", Identifier = "B" }, } }; var expected = new WebResponse <SourceSystem> { Code = HttpStatusCode.OK, Message = entity, Tag = "1" }; requester.Setup(x => x.Request <SourceSystem>(It.IsAny <string>())).Returns(expected); var identifier = new Mapping { SystemName = "Trayport", Identifier = "A" }; // Act var candidate = service.Get(identifier); // Assert Assert.AreSame(expected, candidate, "Entities differ"); }
public void GetByIdValidAt() { var requester = new Mock <IMessageRequester>(); var service = new MdmEntityService <SourceSystem>("sourcesystem", requester.Object); var entity = new SourceSystem { Details = new SourceSystemDetails { Name = "Gas" }, Identifiers = new MdmIdList { new MdmId { SystemName = "Nexus", Identifier = "1", IsMdmId = true }, new MdmId { SystemName = "Trayport", Identifier = "A" }, new MdmId { SystemName = "Endur", Identifier = "B" }, } }; var expected = new WebResponse <SourceSystem> { Code = HttpStatusCode.OK, Message = entity, Tag = "1" }; requester.Setup(x => x.Request <SourceSystem>(It.IsAny <string>())).Returns(expected); var now = DateTime.Now; string dateFormatString = "yyyy-MM-dd'T'HH:mm:ss.fffffffZ"; // Act service.Get(1, now); // Assert requester.Verify(x => x.Request <SourceSystem>(It.Is <string>(s => s.Split('?')[1].Contains("as-of=" + now.ToString(dateFormatString)))), Times.Once()); }
public void GetMissingEntityById() { var requester = new Mock <IMessageRequester>(); var service = new MdmEntityService <SourceSystem>("sourcesystem", requester.Object); var response = new WebResponse <SourceSystem> { Code = HttpStatusCode.NotFound, IsValid = false, Message = null, Tag = "1" }; requester.Setup(x => x.Request <SourceSystem>(It.IsAny <string>())).Returns(response); // Act var candidate = service.Get(1); // Assert Assert.AreSame(response, candidate); }
public void GetByMappingUrlEncodesCorrectly() { var requester = new Mock <IMessageRequester>(); var service = new MdmEntityService <SourceSystem>("sourcesystem", requester.Object); var entity = new SourceSystem { Details = new SourceSystemDetails { Name = "Gas" }, Identifiers = new MdmIdList { new MdmId { SystemName = "Trayport", Identifier = "1&1" }, } }; var expected = new WebResponse <SourceSystem> { Code = HttpStatusCode.OK, Message = entity, Tag = "1" }; requester.Setup(x => x.Request <SourceSystem>(It.IsAny <string>())).Returns(expected); var identifier = new Mapping { SystemName = "S&P", Identifier = "1&1" }; // Act var candidate = service.Get(identifier); // Assert requester.Verify(x => x.Request <SourceSystem>("sourcesystem/map?source-system=S%26P&mapping-string=1%261")); }
public void GetMissingEntityById() { var requester = new Mock<IMessageRequester>(); var service = new MdmEntityService<SourceSystem>("sourcesystem", requester.Object); var response = new WebResponse<SourceSystem> { Code = HttpStatusCode.NotFound, IsValid = false, Message = null, Tag = "1" }; requester.Setup(x => x.Request<SourceSystem>(It.IsAny<string>())).Returns(response); // Act var candidate = service.Get(1); // Assert Assert.AreSame(response, candidate); }
public void GetByMappingUrlEncodesCorrectly() { var requester = new Mock<IMessageRequester>(); var service = new MdmEntityService<SourceSystem>("sourcesystem", requester.Object); var entity = new SourceSystem { Details = new SourceSystemDetails { Name = "Gas" }, Identifiers = new MdmIdList { new MdmId { SystemName = "Trayport", Identifier = "1&1"}, } }; var expected = new WebResponse<SourceSystem> { Code = HttpStatusCode.OK, Message = entity, Tag = "1" }; requester.Setup(x => x.Request<SourceSystem>(It.IsAny<string>())).Returns(expected); var identifier = new Mapping { SystemName = "S&P", Identifier = "1&1" }; // Act var candidate = service.Get(identifier); // Assert requester.Verify(x => x.Request<SourceSystem>("sourcesystem/map?source-system=S%26P&mapping-string=1%261")); }
public void GetByMapping() { var requester = new Mock<IMessageRequester>(); var service = new MdmEntityService<SourceSystem>("sourcesystem", requester.Object); var entity = new SourceSystem { Details = new SourceSystemDetails { Name = "Gas" }, Identifiers = new MdmIdList { new MdmId { SystemName = "Nexus", Identifier = "1", IsMdmId = true}, new MdmId { SystemName = "Trayport", Identifier = "A"}, new MdmId { SystemName = "Endur", Identifier = "B"}, } }; var expected = new WebResponse<SourceSystem> { Code = HttpStatusCode.OK, Message = entity, Tag = "1" }; requester.Setup(x => x.Request<SourceSystem>(It.IsAny<string>())).Returns(expected); var identifier = new Mapping { SystemName = "Trayport", Identifier = "A" }; // Act var candidate = service.Get(identifier); // Assert Assert.AreSame(expected, candidate, "Entities differ"); }
public void GetByIdValidAt() { var requester = new Mock<IMessageRequester>(); var service = new MdmEntityService<SourceSystem>("sourcesystem", requester.Object); var entity = new SourceSystem { Details = new SourceSystemDetails { Name = "Gas" }, Identifiers = new MdmIdList { new MdmId { SystemName = "Nexus", Identifier = "1", IsMdmId = true}, new MdmId { SystemName = "Trayport", Identifier = "A"}, new MdmId { SystemName = "Endur", Identifier = "B"}, } }; var expected = new WebResponse<SourceSystem> { Code = HttpStatusCode.OK, Message = entity, Tag = "1" }; requester.Setup(x => x.Request<SourceSystem>(It.IsAny<string>())).Returns(expected); var now = DateTime.Now; string dateFormatString = "yyyy-MM-dd'T'HH:mm:ss.fffffffZ"; // Act service.Get(1, now); // Assert requester.Verify(x => x.Request<SourceSystem>(It.Is<string>(s => s.Split('?')[1].Contains("as-of=" + now.ToString(dateFormatString)))), Times.Once()); }