static void Main(string[] args) { using (var ctx = new ASAEntitiesContext()) { //Sender sen = new Sender() //{ // Title = "mr", // ForName1 = "Sat", // ForName2 = "Ch", // SurName = "Gat", // Email = "*****@*****.**", // AddressLine1 = "awdas", // AddressLine2 = "asdasdsa", // AddressLine3 = "www", // Country = "UK", // Postcode = "E11", // Mobile = "01111", // SenderPassword = "******", // Telephone = "5131", // Type = SenderType.Individual, // HMRCUserId = "VATDEC180a01", // HMRCPassword = "******" //}; //ctx.Sender.Add(sen); //ctx.SaveChanges(); GovTalkMessage msg = new GovTalkMessage() { }; //SuccessResponseIRmarkReceipt ir = new SuccessResponseIRmarkReceipt //{ //}; //SuccessResponse resp = new SuccessResponse() //{ // //IRmarkReceipt = ir, // AcceptedTime = DateTime.Now, // AcceptedTimeSpecified = true, // ResponseData_IsEmpty = true, //}; //ctx.SucessResponse.Add(resp); ctx.SaveChanges(); Client clt = new Client() { Name = "London Borough Of Redbride", RegNo = "Reg123456789", VATNo = "VAT123456" }; ctx.Client.Add(clt); ctx.SaveChanges(); Business bu = new Business() { BusinessName = "TEST", BusinessId = 1, TradingName = "TEST", RegisteredDate = DateTime.Now, VATRegNo = "123456", SenderId = 1 }; BusinessAddress bud = new BusinessAddress() { Line1 = "test", Line2 = "test2", Line3 = "test3", Line4 = "test5", Postcode = "IG1", Country = "UK" }; bu.BusinessAddress = bud; //ctx.BusinessAddress.Add(bud); //ctx.Business.Add(bu); // ctx.SaveChanges(); PeriodData per = new PeriodData() { StartPeriod = DateTime.Now.AddMonths(-3), EndPeriod = DateTime.Now, PeriodrefId = "2017-04", Status = SubmissionStatus.Draft }; VAT100 vat = new VAT100() { }; //per.VAT100 = vat; bu.Periods.Add(per); Client cl = new Client() { //Id = 1, Name = "consoleC", RegNo = "123", VATNo = "1234567" }; ClientAddress cd = new ClientAddress() { Address1 = "First line of add", Address2 = "Second line of add", City = "Lonodn", ClientAddressId = 1, Country = "UK", PostCode = "SS1", }; PeriodData per1 = new PeriodData() { StartPeriod = DateTime.Now.AddMonths(-3), EndPeriod = DateTime.Now, PeriodrefId = "2017-07", Status = SubmissionStatus.Draft }; bu.Periods.Add(per1); //works above cl.ClientAddress = cd; //ctx.Client.Add(cl); //ctx.SaveChanges(); //ctx.SaveChanges(); //var cup = ctx.ClientAddress.FirstOrDefault(); //cup.Address1 = "New Update address"; //var c = ctx.Client.FirstOrDefault(); //c.ClientAddress = cup; //ctx.Client.Add(c); // ctx.Client.Add(cl); InvoiceDetail invd = new InvoiceDetail(); invd.No = "LBR-1"; invd.IssueDate = DateTime.Now; invd.DueDate = DateTime.Now.AddDays(7); invd.Note = "test"; invd.Ref = "nothing"; invd.Discount = "10%"; InvoiceItem item = new InvoiceItem(); var itemguid = Guid.Parse("00000000-0000-0000-0000-000000000000"); item.Id = itemguid; item.Description = "apple"; item.Quantity = "1"; item.Price = "1"; item.Total = "1"; item.SubTotal = "1"; item.VAT = "0"; item.VATRate = "0"; List <InvoiceItem> items = new List <InvoiceItem>(); items.Add(item); var myguid = Guid.Parse("3551A09E-DE21-A325-6DF4-40281A4FEBE0"); //var inv = ctx.Invoice.Where(i => i.InvoiceId == myguid) // .Include(d => d.InvoiceDetail) // .Include(it => it.InvoiceItems) // .FirstOrDefault(); //ctx.Entry(inv).CurrentValues.SetValues(inv); //foreach (var it in items) //{ // var existingChild = inv.InvoiceItems.Where(c => c.Id == it.Id).SingleOrDefault(); // if(existingChild!=null) // { // ctx.Entry(existingChild).CurrentValues.SetValues(it); // } // else // { // Console.WriteLine("add new item"); // inv.InvoiceItems.Add(item); // } //} //ctx.Entry(inv).State = EntityState.Modified; //Invoice myinvoice = new Invoice(); //myinvoice.ClientId = 3; //myinvoice.InvoiceDetail = invd; //myinvoice.InvoiceItems = items; //ctx.Invoice.Add(myinvoice); //ctx.SaveChanges(); // bu.Periods.Add(per1); // ctx.Business.Add(bu); //cl.ClientAddress = cd; //ctx.Client.Add(cl); //ctx.SaveChanges(); } }
public HttpResponseMessage Post(SubmissionViewModel model) { if (ModelState.IsValid) //always returning true { string testInLive = model.RunMode; bool mode = testInLive.Equals("1") ? true : false; var sender = new Sender { Title = model.BussinessViewModel.Sender.Title, ForName1 = model.BussinessViewModel.Sender.ForName1, ForName2 = model.BussinessViewModel.Sender.ForName2, SurName = model.BussinessViewModel.Sender.SurName, Email = model.BussinessViewModel.Sender.Email, AddressLine1 = model.BussinessViewModel.Sender.AddressLine1, AddressLine2 = model.BussinessViewModel.Sender.AddressLine2, AddressLine3 = model.BussinessViewModel.Sender.AddressLine3, Postcode = model.BussinessViewModel.Sender.Postcode, SenderPassword = model.BussinessViewModel.Sender.SenderPassword, Type = model.BussinessViewModel.Sender.Type, Mobile = model.BussinessViewModel.Sender.Mobile, Telephone = model.BussinessViewModel.Sender.Telephone, HMRCPassword = model.BussinessViewModel.Sender.HMRCPassword, HMRCUserId = model.BussinessViewModel.Sender.HMRCUserId, Country = model.BussinessViewModel.Sender.Country, SenderId = model.BussinessViewModel.Sender.SenderId }; var address = new BusinessAddress { Line1 = model.BussinessViewModel.BusinessAddress.Line1, Line2 = model.BussinessViewModel.BusinessAddress.Line2, Line3 = model.BussinessViewModel.BusinessAddress.Line3, Line4 = model.BussinessViewModel.BusinessAddress.Line4, Country = model.BussinessViewModel.BusinessAddress.Country, Postcode = model.BussinessViewModel.BusinessAddress.Postcode, BusinessAddressId = model.BussinessViewModel.BusinessAddress.BusinessAddressId }; var business = new Business { BusinessName = model.BussinessViewModel.BusinessName, RegisteredDate = model.BussinessViewModel.RegisteredDate, VATRegNo = model.BussinessViewModel.VATRegNo, TradingName = model.BussinessViewModel.TradingName, BusinessId = model.BussinessViewModel.BusinessId, RegNo = model.BussinessViewModel.RegNo, VATRate = model.BussinessViewModel.VATRate, SenderId = model.BussinessViewModel.SenderId }; var perioddata = new PeriodData { PeriodrefId = model.PeriodViewModel.PeriodRefId, StartPeriod = model.PeriodViewModel.StartPeriod, EndPeriod = model.PeriodViewModel.EndPeriod, PeriodId = model.PeriodViewModel.PeriodId, BusinessId = model.BussinessViewModel.BusinessId }; var vatData = new VAT100() { Box1 = model.VAT100ViewModel.VATDueOnOutputs.ToString("N"), Box2 = model.VAT100ViewModel.VATDueOnECAcquisitions.ToString("N"), Box3 = model.VAT100ViewModel.TotalVAT.ToString("N"), Box4 = model.VAT100ViewModel.VATReclaimedOnInputs.ToString("N"), Box5 = model.VAT100ViewModel.NetVAT.ToString("N"), Box6 = model.VAT100ViewModel.NetSalesAndOutputs.ToString(), Box7 = model.VAT100ViewModel.NetPurchasesAndInputs.ToString(), Box8 = model.VAT100ViewModel.NetECSupplies.ToString(), Box9 = model.VAT100ViewModel.NetECAcquisitions.ToString(), LastUpdated = model.VAT100ViewModel.LastUpdated }; SubmissionManager submissionmanager = new SubmissionManager(_gatewayService); //create govtalk message var submissionResponse = submissionmanager.SendSubmissionRequest(sender, business, perioddata, vatData, mode); //read correlationId and poll uri from response //TODO: every time it fails delete the request and resubmit on sucess capt response and send back to client // List<Object> responses = new List<Object>(); Dictionary <string, List <XElement> > dicresponses = new Dictionary <string, List <XElement> >(); if (submissionResponse.Errors.Count == 0) { //submission passes send poll request string correlationId = submissionResponse.CorrelationId.ToString(); string polluri = submissionResponse.FollowOnUri.ToString(); if (!(String.IsNullOrEmpty(correlationId) && String.IsNullOrEmpty(polluri))) { var pollResponse = submissionmanager.SendPollRequest(correlationId, polluri, mode); if (pollResponse.Errors.Count == 0) { //success get success response perioddata.Status = SubmissionStatus.Accepted; //update status as accepted by HMRC and VAT info in the vat table perioddata.VAT100 = vatData; // attaching new vat data to update //perioddata.HmrcResponses.Add(pollResponse); var nextQuaterStartDate = submissionmanager.AddMonthsCustom(perioddata.StartPeriod, 3); var nextQuaterEndDate = submissionmanager.AddMonthsCustom(perioddata.EndPeriod, 3); var nextPeriod = new PeriodData() { StartPeriod = nextQuaterStartDate, EndPeriod = nextQuaterEndDate, BusinessId = business.BusinessId, PeriodrefId = nextQuaterEndDate.ToString("yyyy-MM"), Status = SubmissionStatus.Draft }; business.BusinessAddress = address; business.Sender = sender; business.NextQuaterStartDate = nextQuaterStartDate; //update bussiness model props with next quater start and end dates business.NextQuaterEndDate = nextQuaterEndDate; perioddata.HmrcResponses.Add(pollResponse); business.Periods.Add(perioddata); business.Periods.Add(nextPeriod); _gatewayService.UpdateEntities(business); // _gatewayService.Save(pollResponse); var strContent = HelperMethods.ExtractBodyContent(pollResponse.ResponseData.ToString()); var successResponse = HelperMethods.Deserialize <SuccessResponse>(strContent); //save the response in the DB //_gatewayService.AddNextQuaterPeriod(nextPeriod); //Add next VAT quater in the database //business.Periods.Add(nextPeriod); //_gatewayService.UpdateNextQuaterInBVM(business); // _gatewayService.SaveResponse(successResponse); // commit to DB after adding all above objects to repositories //if (successResponse != null) //{ //TODO: serialise sucessresponse, sucessresponseirmark, message type var str = HelperMethods.Serialize(successResponse); var xdoc = XDocument.Parse(str, LoadOptions.PreserveWhitespace); ////select only body element from xdoc var hmrcresponsemsgnode = (from d in xdoc.Descendants() where d.Name.LocalName == "Message" select d).ToList(); var vatperiodnode = (from m in xdoc.Descendants() where m.Name.LocalName == "VATPeriod" select m).ToList(); var paymentBodyNode = (from p in xdoc.Descendants() where p.Name.LocalName == "Body" select p).ToList(); var errorsNode = (from p in xdoc.Descendants() where p.Name.LocalName == "Error" select p).ToList(); dicresponses.Add("hmrcResponse", hmrcresponsemsgnode); dicresponses.Add("vatPeriod", vatperiodnode); dicresponses.Add("paymentDetails", paymentBodyNode); dicresponses.Add("Errors", errorsNode); //responses.Add(successResponse); return(Request.CreateResponse <Dictionary <string, List <XElement> > >(HttpStatusCode.OK, dicresponses)); } else { //failure bus valid failed handle here //delete the request and resubmit as new request as mentioned in the gov site submissionmanager.SendDeleteRequest(correlationId, mode, polluri); var temp = XDocument.Parse(pollResponse.ResponseData); var pollerrors = (from p in temp.Descendants() where p.Name.LocalName == "Error" select p).ToList(); dicresponses.Add("Errors", pollerrors); // responses.Add(pollResponse); } } else { //id or uri is null // responses.Add(submissionResponse); var temp = XDocument.Parse(submissionResponse.ResponseData); var submissionerrors = (from p in temp.Descendants() where p.Name.LocalName == "Error" select p).ToList(); dicresponses.Add("Errors", submissionerrors); return(Request.CreateResponse <Dictionary <string, List <XElement> > >(HttpStatusCode.BadRequest, dicresponses)); } } else { //return submission failure response // responses.Add(submissionResponse); var temp = XDocument.Parse(submissionResponse.ResponseData); var submissionerrors = (from p in temp.Descendants() where p.Name.LocalName == "Error" select p).ToList(); dicresponses.Add("Errors", submissionerrors); } return(Request.CreateResponse <Dictionary <string, List <XElement> > >(HttpStatusCode.OK, dicresponses)); } return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); //} //throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = "data is null" }); }
public GovTalkMessage CreateGovTalkMessage(Sender sender, Business business, PeriodData periodData, VAT100 vatData, bool testInLive) { string classType = !testInLive ? "HMRC-VAT-DEC" : "HMRC-VAT-DEC-TIL"; string gatewayTest = !testInLive ? "0" : "1"; //Gov Talk message GovTalkMessage govTalkMessage = new GovTalkMessage(); //Gov Talk header GovTalkMessageHeader header = new GovTalkMessageHeader(); //sender details GovTalkMessageHeaderSenderDetails senderDetails = new GovTalkMessageHeaderSenderDetails(); GovTalkMessageHeaderSenderDetailsIDAuthentication idauth = new GovTalkMessageHeaderSenderDetailsIDAuthentication(); idauth.SenderID = sender.HMRCUserId; GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthentication aauth = new GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthentication(); aauth.Method = GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthenticationMethod.clear; aauth.Role = "principal"; aauth.Item = sender.HMRCPassword; GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthentication[] authentications = new GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthentication[1]; authentications[0] = aauth; idauth.Authentication = authentications; senderDetails.IDAuthentication = idauth; senderDetails.EmailAddress = sender.Email; //message details GovTalkMessageHeaderMessageDetails messagedetails = new GovTalkMessageHeaderMessageDetails(); messagedetails.Class = classType; messagedetails.Qualifier = GovTalkMessageHeaderMessageDetailsQualifier.request; messagedetails.Function = GovTalkMessageHeaderMessageDetailsFunction.submit; messagedetails.FunctionSpecified = true; messagedetails.CorrelationID = ""; messagedetails.Transformation = GovTalkMessageHeaderMessageDetailsTransformation.XML; messagedetails.GatewayTest = gatewayTest; messagedetails.TransformationSpecified = true; header.MessageDetails = messagedetails; header.SenderDetails = senderDetails; //Gov Talk details GovTalkMessageGovTalkDetails govTalkDetails = new GovTalkMessageGovTalkDetails(); //keys GovTalkMessageGovTalkDetailsKey key = new GovTalkMessageGovTalkDetailsKey(); key.Type = ConfigurationManager.AppSettings["GovTalkDetailsKeyType"]; key.Value = business.VATRegNo.ToString(); GovTalkMessageGovTalkDetailsKey[] keys = new GovTalkMessageGovTalkDetailsKey[1]; keys[0] = key; //Channel routing GovTalkMessageGovTalkDetailsChannelRoutingChannel channel = new GovTalkMessageGovTalkDetailsChannelRoutingChannel(); channel.Version = ConfigurationManager.AppSettings["ChannelVersion"]; channel.Product = ConfigurationManager.AppSettings["ChannelProduct"]; channel.ItemElementName = ItemChoiceType.URI; channel.Item = ConfigurationManager.AppSettings["ChannelUri"]; GovTalkMessageGovTalkDetailsChannelRouting channelRouting = new GovTalkMessageGovTalkDetailsChannelRouting(); channelRouting.Channel = channel; GovTalkMessageGovTalkDetailsChannelRouting[] channelRoutings = new GovTalkMessageGovTalkDetailsChannelRouting[1]; channelRoutings[0] = channelRouting; govTalkDetails.Keys = keys; govTalkDetails.ChannelRouting = channelRoutings; //Gov Talk Body GovTalkMessageBody body = new GovTalkMessageBody(); //populate body content with ir68 data //IR68 ir68 = new IR68(periodData, vatData); //commented out to use method instead of object instantiation with period/vat data //IRenvelope iRenvelope = ir68.CreateIREnvelopeBody(sender, business); IRenvelope iRenvelope = CreateIRenvelopeBody(sender, business, periodData, vatData); //serialse ir object data into xml elements and add to Gov Talk body //XElement xe = XElement.Parse(SerializeIrEnvelope(iRenvelope)); XElement xe = XElement.Parse(IREnvelopeToXDocument(iRenvelope).ToString()); XmlElement xelement = ToXmlElement(xe); XmlElement[] xmlElements = new XmlElement[1]; xmlElements[0] = xelement; body.Any = xmlElements; govTalkMessage.EnvelopeVersion = ConfigurationManager.AppSettings["GovTalkMessageEnvelopeVersion"]; govTalkMessage.Header = header; govTalkMessage.GovTalkDetails = govTalkDetails; govTalkMessage.Body = body; return(govTalkMessage); }
private IRenvelope CreateIRenvelopeBody(Sender sender, Business business, PeriodData periodData, VAT100 vatData) { IRenvelope irenvelope = new IRenvelope(); IRheader irheader = new IRheader(); IRheaderKey irheaderkey = new IRheaderKey { Type = "VATRegNo", Value = business.VATRegNo }; irheader.PeriodID = periodData.PeriodrefId; irheader.Sender = IRheaderSender.Individual; // irheader.PeriodStart = periodData.StartPeriod; //irheader.PeriodEnd = periodData.EndPeriod; IRheaderKey[] irHeaderKeys = new IRheaderKey[1]; irHeaderKeys[0] = irheaderkey; irheader.Keys = irHeaderKeys; VATDeclarationRequest_ContactDetailsStructure contact = new VATDeclarationRequest_ContactDetailsStructure(); VATDeclarationRequest_ContactDetailsStructureName name = new VATDeclarationRequest_ContactDetailsStructureName { Fore = new[] { sender.ForName1, sender.ForName2 }, Sur = sender.SurName, Ttl = sender.Title }; VATDeclarationRequest_ContactDetailsStructureEmail email = new VATDeclarationRequest_ContactDetailsStructureEmail { Preferred = VATDeclarationRequest_YesNoType.yes, PreferredSpecified = true, Type = VATDeclarationRequest_WorkHomeType.work, TypeSpecified = true, Value = sender.Email }; contact.Name = name; VATDeclarationRequest_ContactDetailsStructureEmail[] Emails = new VATDeclarationRequest_ContactDetailsStructureEmail[1]; Emails[0] = email; contact.Email = Emails; IRheaderPrincipal principal = new IRheaderPrincipal { Contact = contact }; irheader.Principal = principal; IRheaderIRmark irmark = new IRheaderIRmark(); irmark.Type = IRheaderIRmarkType.generic; irmark.Value = ""; irheader.IRmark = irmark; VATDeclarationRequest vatreq = new VATDeclarationRequest { VATDueOnOutputs = vatData.Box1, VATDueOnECAcquisitions = vatData.Box2, TotalVAT = vatData.Box3, VATReclaimedOnInputs = vatData.Box4, NetVAT = vatData.Box5, NetSalesAndOutputs = vatData.Box6, NetPurchasesAndInputs = vatData.Box7, NetECSupplies = vatData.Box8, NetECAcquisitions = vatData.Box9 }; //set values here irenvelope.IRheader = irheader; irenvelope.VATDeclarationRequest = vatreq; return(irenvelope); }
public HMRCResponse SendSubmissionRequest(Sender sender, Business business, PeriodData periodData, VAT100 vatData, bool testInLive) { HMRCResponse hmrcResponse = (HMRCResponse)null; if (testInLive) { _submissionUrl = ConfigurationManager.AppSettings["testsubmissionurl"]; } else { _submissionUrl = ConfigurationManager.AppSettings["submissionurl"]; } //create govtalk message var govTalkMessage = _gatewayService.CreateGovTalkMessage(sender, business, periodData, vatData, testInLive); //serailize object to string //var strGovTalkMessage = HelperMethods.Serialize(govTalkMessage); var strGovTalkMessage = HelperMethods.GovTalkMessageToXDocument(govTalkMessage).ToString(); //generate irmark from govtalk message byte[] bytes = Encoding.UTF8.GetBytes(strGovTalkMessage); //var iREnvelopeBody = _gatewayService.CreateIRenvelopeBody(sender, business, perioddata, vatData); var irmark = HelperMethods.GetIRMark(bytes); XDocument xdoc; //set irmark value to the govtalk message body if (irmark != null) { xdoc = XDocument.Parse(strGovTalkMessage, LoadOptions.PreserveWhitespace); //xdoc.Save("Without.xml"); if (xdoc.Root != null) { XNamespace ns = xdoc.Root.Name.Namespace; XElement body = xdoc.Root.Element(ns + "Body"); if (body != null) { var bodyElelemts = from el in body.Descendants() where el.Name.LocalName == "IRenvelope" select el; foreach (var ele in bodyElelemts) { XNamespace ns1 = ele.Name.Namespace; var element = ele.Descendants(ns1 + "IRmark").First(); if (element != null) { element.Value = irmark; } } } } string strSendRequest = xdoc.ToString(); this._filename = business.BusinessName.ToString(); this._path = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/ClientData"), _filename); bool folderexists = CreateBusDir(_path); bool periodexists = CreatePerdiodDir(_path + "\\" + periodData.PeriodrefId); this._filepath = _path + "\\" + periodData.PeriodrefId; if (folderexists == true && periodexists) { Log(strSendRequest, _filepath, "submission_Request"); //System.IO.StreamWriter file = new System.IO.StreamWriter(_filepath +"\\" + "submissionrequest.xml"+DateTime.Now); //file.WriteLine(strSendRequest); //file.Close(); } hmrcResponse = _gatewayService.SendHMRCMessage(strSendRequest, _submissionUrl); if (_filepath != null && hmrcResponse.ResponseData != null) { if (hmrcResponse.Type.ToString() == "error") { Log(hmrcResponse.ResponseData, _filepath, "submission_Error"); } else if (hmrcResponse.Type.ToString() == "acknowledgement") { Log(hmrcResponse.ResponseData, _filepath, "submission_Acknowledgement"); } else { Log(hmrcResponse.ResponseData, _filepath, "submission_Response"); } } return(hmrcResponse); } return(null); }
public void Submission_SendRequest() { //Arrange //Fake input params var sen = new Sender { Title = "Mr", ForName1 = "Sat", ForName2 = "aa", SurName = "Gat", AddressLine1 = "133Gleny", AddressLine2 = "Barking", Postcode = "Ig11", Country = "UK", Email = "*****@*****.**", Mobile = "0123456789", HMRCUserId = "VATDEC180a01", SenderPassword = "******" }; var bus = new Business { BusinessName = "ABC", RegisteredDate = DateTime.Parse("07-04-2017"), TradingName = "ABC", VATRegNo = "999900001", }; var add = new BusinessAddress { Line1 = "1 First Add", Line2 = "2 Second add", Line3 = "3 Third", Postcode = "Ig11", Country = "UK" }; // bus.AddressList.Add(add); var per = new PeriodData { PeriodrefId = "201701", StartPeriod = DateTime.Parse("07-04-2017"), EndPeriod = DateTime.Parse("31-07-2017") }; var vat = new VAT100 { Box1 = "1.50", Box2 = "0.50", Box3 = "2.00", Box4 = "2.00", Box5 = "0.00", Box6 = "20", Box7 = "10", Box8 = "10", Box9 = "5" }; //Arrange //var sm = new SubmissionManager(_gatewayService); // var test = sm.SendSubmissionRequest(sen, bus, per, vat, true); //Act //var govtalkmessage = _gatewayService.CreateGovTalkMessage(sen, bus, per, vat, true); // var strGovTalkMessage = HelperMethods.GovTalkMessageToXDocument(govtalkmessage).ToString(); ////generate irmark from govtalk message //byte[] bytes = Encoding.UTF8.GetBytes(strGovTalkMessage); // var irmark = HelperMethods.GetIRMark(bytes); // var xdoc = XDocument.Parse(strGovTalkMessage, LoadOptions.PreserveWhitespace); //set irmark value in the doc // if (irmark!=null) // { // XNamespace ns = xdoc.Root.Name.Namespace; // XElement body = xdoc.Root.Element(ns + "Body"); // if (body != null) // { // var bodyElelemts = from el in body.Descendants() // where el.Name.LocalName == "IRenvelope" // select el; // foreach (var ele in bodyElelemts) // { // XNamespace ns1 = ele.Name.Namespace; // var element = ele.Descendants(ns1 + "IRmark").First(); // if (element != null) // { // element.Value = irmark; // } // } // } // } // string strSendRequest = xdoc.ToString(); //TODO: Need to validate the xml before sending to gateway but this seems to be complicate yet as //this needs to be validate individual classes irenvelope and vat payload and govtlak envelope so for future //http://stackoverflow.com/questions/751511/validating-an-xml-against-referenced-xsd-in-c-sharp // bool result = HelperMethods.IsValidXml(strSendRequest, @"C:\Temp\ASA.API\ASA.Core\XSDs\envelope-v2-0-HMRC.xsd", "http://www.govtalk.gov.uk/CM/envelope"); //var submissionResponse = sm.SendSubmissionRequest(sen, bus, per, vat, true); //var erorrs = submissionResponse.Errors.Count; string correlationId = "585F0728964645B2A944B4410D0EF5A8"; string polluri = "https://secure.dev.gateway.gov.uk/poll"; var govTalkMessageForPoll = _gatewayService.CreateGovTalkMessageForPollRequest(correlationId, polluri, true); var pollreq = HelperMethods.GoVTalkMessageToXDocumentForPoll(govTalkMessageForPoll); var pollStr = pollreq.ToString(); var pollresponse = _gatewayService.SendHMRCMessage(pollStr, polluri); var strContent = HelperMethods.ExtractBodyContent(pollresponse.ResponseData.ToString()); var successResponse = HelperMethods.Deserialize <SuccessResponse>(strContent); var str = HelperMethods.Serialize(successResponse); var doc = XDocument.Parse(str, LoadOptions.PreserveWhitespace); ////select only body element from xdoc XNamespace nsr = "http://www.govtalk.gov.uk/taxation/vat/vatdeclaration/2"; var hmrcresponsemsgnode = (from d in doc.Descendants() where d.Name.LocalName == "Message" select d).ToList(); var messagedetailsnode = (from m in doc.Descendants() where m.Name.LocalName == "AcceptedTime" select m).ToList(); var paymentBodyNode = (from p in doc.Descendants() where p.Name.LocalName == "Body" select p).ToList(); List <XElement> col = new List <XElement>(); col.AddRange(hmrcresponsemsgnode); col.AddRange(messagedetailsnode); col.AddRange(paymentBodyNode); Dictionary <string, List <XElement> > dic = new Dictionary <string, List <XElement> >(); dic.Add("hmrcResponseNode", hmrcresponsemsgnode); dic.Add("password", messagedetailsnode); dic.Add("plan_id", paymentBodyNode); //Asset // Assert.IsInstanceOfType(govtalkmessage, typeof(GovTalkMessage)); //check if the object is govTalkMessage //Assert.IsTrue(result); //validate generated xml // Assert.AreEqual(erorrs, 0); }