public void When_Saving_Header_With_Multiple_Names_Then_Insert_Name_Is_Called_For_Each_Name() { // arrange const int headerKey = 1; var header = new Type814Header(); header.AddName(new Type814Name { EntityIdCode = "mock_one", }); header.AddName(new Type814Name { EntityIdCode = "mock_two", }); header.AddName(new Type814Name { EntityIdCode = "mock_three", }); dataAccess.Stub(x => x.InsertHeader(Arg.Is(header))) .Return(headerKey); dataAccess.Expect(x => x.InsertName(Arg <Type814Name> .Is.TypeOf)) .Return(1); // act concern.SaveHeader(header); // assert Assert.IsTrue(header.Names.All(x => x.HeaderKey.Equals(headerKey))); dataAccess.AssertWasCalled(x => x.InsertName(null), x => x.IgnoreArguments().Repeat.Times(3, 3)); dataAccess.VerifyAllExpectations(); }
public void When_Saving_Header_With_Any_Names_Then_Insert_Name_Is_Called() { // arrange const int headerKey = 1; var name = new Type814Name { EntityIdCode = "mock", }; var header = new Type814Header(); header.AddName(name); dataAccess.Stub(x => x.InsertHeader(Arg.Is(header))) .Return(headerKey); dataAccess.Expect(x => x.InsertName(Arg.Is(name))) .Return(1); // act concern.SaveHeader(header); // assert Assert.AreEqual(headerKey, name.HeaderKey); dataAccess.VerifyAllExpectations(); }
public Type814Header ParseHeader(XElement element, IDictionary <string, XNamespace> namespaces) { XNamespace empty; if (!namespaces.TryGetValue(string.Empty, out empty)) { empty = XNamespace.None; } var model = new Type814Header { TransactionSetId = element.GetChildText(empty + "TransactionSetId"), TransactionSetControlNbr = element.GetChildText(empty + "TransactionSetControlNbr"), TransactionSetPurposeCode = element.GetChildText(empty + "TransactionSetPurposeCode"), TransactionNbr = element.GetChildText(empty + "TransactionNbr"), TransactionDate = element.GetChildText(empty + "TransactionDate"), TransactionTime = element.GetChildText(empty + "TransactionTime"), TransactionTimeCode = element.GetChildText(empty + "TransactionTimeCode"), ReferenceNbr = element.GetChildText(empty + "ReferenceNbr"), ActionCode = element.GetChildText(empty + "ActionCode"), TdspDuns = element.GetChildText(empty + "TdspDuns"), TdspName = element.GetChildText(empty + "TdspName"), CrDuns = element.GetChildText(empty + "CrDuns"), CrName = element.GetChildText(empty + "CrName"), TransactionQualifier = element.GetChildText(empty + "TransactionQualifier"), }; var nameLoopElement = element.Element(empty + "NameLoop"); if (nameLoopElement != null) { var nameElements = nameLoopElement.Elements(empty + "Name"); foreach (var nameElement in nameElements) { var nameModel = ParseName(nameElement, namespaces); model.AddName(nameModel); } } var serviceLoopElement = element.Element(empty + "ServiceLoop"); if (serviceLoopElement != null) { var serviceElements = serviceLoopElement.Elements(empty + "Service"); foreach (var serviceElement in serviceElements) { var serviceModel = ParseService(serviceElement, namespaces); model.AddService(serviceModel); } } if (model.Services.Any()) { var firstServiceModel = model.Services[0]; var transactionTypeId = marketDataAccess .IdentifyTransactionType(model.ActionCode, firstServiceModel.ActionCode); model.TransactionTypeId = transactionTypeId; } return(model); }