Ejemplo n.º 1
0
        public void When_Saving_Header_With_Any_Services_Then_Insert_Service_Is_Called()
        {
            // arrange
            const int headerKey = 1;

            var service = new Type814Service {
                ServiceType1 = "mock"
            };

            var header = new Type814Header();

            header.AddService(service);

            dataAccess.Stub(x => x.InsertHeader(Arg.Is(header)))
            .Return(headerKey);

            dataAccess.Expect(x => x.InsertService(Arg.Is(service)))
            .Return(1);

            // act
            concern.SaveHeader(header);

            // assert
            Assert.AreEqual(headerKey, service.HeaderKey);
            dataAccess.VerifyAllExpectations();
        }
Ejemplo n.º 2
0
        public void WriteServiceHistoricalUsageRequest(Prism814Context context, Type814Header header, Type814Service[] services)
        {
            foreach (var service in services)
            {
                if (!service.ServiceKey.HasValue)
                {
                    continue;
                }

                var crDuns = string.Empty;
                if (context.Market != MarketOptions.Texas)
                {
                    crDuns = header.CrDuns;
                }

                var membershipId = IdentifyLdcAccountNumber(context, service);

                var line =
                    string.Format(
                        "10|{0}|{1}|{2}|{3}|{4}|E|||{5}|||{11}||||||||||{6}||||||||{7}|{8}|||||||||||{9}|||{10}|||{12}|",
                        context.TradingPartnerId, service.ServiceType1, service.ServiceType2, service.ServiceType3,
                        header.TransactionNbr, membershipId, service.NotificationWaiver, service.BillType,
                        service.BillCalculator, service.ServiceType4, service.PriorityCode, crDuns,
                        service.FundsAuthorization);

                context.AppendLine(line);
                logger.TraceFormat("Wrote 814 \"10\" PRISM line for Header {0}", header.HeaderKey);
            }
        }
Ejemplo n.º 3
0
        public void When_Saving_Header_With_Any_Service_Meters_Then_Insert_Service_Meter_Is_Called()
        {
            // arrange
            const int serviceKey = 2;

            var meter = new Type814ServiceMeter {
                MeterNumber = "mock"
            };

            var service = new Type814Service();

            service.AddMeter(meter);

            var header = new Type814Header();

            header.AddService(service);

            dataAccess.Stub(x => x.InsertHeader(Arg.Is(header)))
            .Return(1);

            dataAccess.Stub(x => x.InsertService(Arg.Is(service)))
            .Return(serviceKey);

            dataAccess.Expect(x => x.InsertServiceMeter(Arg.Is(meter)))
            .Return(1);

            // act
            concern.SaveHeader(header);

            // assert
            Assert.AreEqual(serviceKey, meter.ServiceKey);

            dataAccess.VerifyAllExpectations();
        }
Ejemplo n.º 4
0
        public void WriteServiceByMaintenanceTypeCode(Prism814Context context, Type814Header header, Type814Service[] services)
        {
            if (string.IsNullOrWhiteSpace(context.ActionCode))
            {
                return;
            }

            var actionCode = context.ActionCode.TrimStart('0');

            switch (actionCode)
            {
            case "E":
                WriteServiceEnrollment(context, header, services);
                break;

            case "C":
                WriteServiceChange(context, header, services);
                break;

            case "7":
            case "D":
                WriteServiceDrop(context, header, services);
                break;

            case "HU":
                WriteServiceHistoricalUsageRequest(context, header, services);
                break;
            }
        }
Ejemplo n.º 5
0
        public void When_Saving_Header_With_No_Service_Meter_TOUs_Then_Insert_Service_Meter_Tou_Is_Not_Called()
        {
            // arrange
            var meter   = new Type814ServiceMeter();
            var service = new Type814Service();
            var header  = new Type814Header();

            service.AddMeter(meter);
            header.AddService(service);

            dataAccess.Stub(x => x.InsertHeader(Arg.Is(header)))
            .Return(1);

            dataAccess.Stub(x => x.InsertService(Arg.Is(service)))
            .Return(1);

            dataAccess.Stub(x => x.InsertServiceMeter(Arg.Is(meter)))
            .Return(1);

            // act
            concern.SaveHeader(header);

            // assert
            dataAccess.AssertWasNotCalled(x => x.InsertServiceMeterTou(null), x => x.IgnoreArguments());
        }
Ejemplo n.º 6
0
        public void WriteServiceChangeResponse(Prism814Context context, Type814Header header, Type814Service[] services)
        {
            var actionCode = context.ActionCode.TrimStart('0');

            foreach (var service in services)
            {
                if (!service.ServiceKey.HasValue)
                {
                    continue;
                }

                var membershipId      = IdentifyLdcAccountNumber(context, service);
                var premiseNumber     = IdentifyEsiId(context, service);
                var serviceActionCode = string.Empty;

                if (actionCode.Equals("PD", StringComparison.Ordinal))
                {
                    serviceActionCode = "A";
                }

                var line =
                    string.Format("10|{0}|{1}|{2}||1|C|{3}||{4}||||||||||||||||||||||||||||||||||{5}|||||",
                                  context.TradingPartnerId, service.ServiceType1, service.ServiceType2, serviceActionCode,
                                  membershipId, premiseNumber);

                context.AppendLine(line);
                logger.TraceFormat("Wrote 814 \"10\" PRISM line for Header {0}", header.HeaderKey);
            }
        }
Ejemplo n.º 7
0
        public void When_Saving_Header_With_Any_Service_Account_Changes_Then_Insert_Service_Account_Change_Is_Called()
        {
            // arrange
            const int serviceKey = 2;

            var change = new Type814ServiceAccountChange {
                ChangeReason = "mock"
            };

            var service = new Type814Service();

            service.AddChange(change);

            var header = new Type814Header();

            header.AddService(service);

            dataAccess.Stub(x => x.InsertHeader(Arg.Is(header)))
            .Return(1);

            dataAccess.Stub(x => x.InsertService(Arg.Is(service)))
            .Return(serviceKey);

            dataAccess.Expect(x => x.InsertServiceAccountChange(Arg.Is(change)))
            .Return(1);

            // act
            concern.SaveHeader(header);

            // assert
            Assert.AreEqual(serviceKey, change.ServiceKey);

            dataAccess.VerifyAllExpectations();
        }
Ejemplo n.º 8
0
        public void When_Saving_Header_With_Any_Service_Rejects_Then_Insert_Service_Reject_Is_Called()
        {
            // arrange
            const int serviceKey = 2;

            var reject = new Type814ServiceReject {
                RejectCode = "mock"
            };

            var service = new Type814Service();

            service.AddReject(reject);

            var header = new Type814Header();

            header.AddService(service);

            dataAccess.Stub(x => x.InsertHeader(Arg.Is(header)))
            .Return(1);

            dataAccess.Stub(x => x.InsertService(Arg.Is(service)))
            .Return(serviceKey);

            dataAccess.Expect(x => x.InsertServiceReject(Arg.Is(reject)))
            .Return(1);

            // act
            concern.SaveHeader(header);

            // assert
            Assert.AreEqual(serviceKey, reject.ServiceKey);

            dataAccess.VerifyAllExpectations();
        }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
        public void WriteServiceReinstatement(Prism814Context context, Type814Header header, Type814Service[] services)
        {
            var actionCode = context.ActionCode.TrimStart('0');

            foreach (var service in services)
            {
                if (!service.ServiceKey.HasValue)
                {
                    continue;
                }

                var premiseNumber = IdentifyEsiId(context, service);
                var line          = string.Format("10|{0}|{1}|{2}||1|R|{3}||||||||||||||||||||||||||||||||||||{4}|||||",
                                                  context.TradingPartnerId, service.ServiceType1, service.ServiceType2, service.ActionCode,
                                                  premiseNumber);

                context.AppendLine(line);
                logger.TraceFormat("Wrote 814 \"10\" PRISM line for Header {0}", header.HeaderKey);

                if (actionCode.Equals("9"))
                {
                    WriteServiceReject(context, service);
                }

                WriteServiceStatus(context, service);
            }
        }
Ejemplo n.º 12
0
        public Type814Header[] ListUnprocessed(string ldcDuns, string duns, int providerId)
        {
            using (var connection = new SqlConnection(connectionString))
                using (var command = connection.CreateCommand("esp_814ExportList"))
                {
                    command.AddIfNotEmptyOrDbNull("@CrDuns", duns)
                    .AddIfNotEmptyOrDbNull("@TDSPDuns", ldcDuns);

                    if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                    }

                    var collection = new List <Type814Header>();
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var item = new Type814Header
                            {
                                HeaderKey   = reader.GetInt32("814_Key"),
                                Direction   = reader.GetBoolean("Direction"),
                                ProcessFlag = reader.GetInt16("ProcessFlag"),
                            };

                            reader.TryGetString("TransactionSetId", x => item.TransactionSetId = x);
                            reader.TryGetString("TransactionSetControlNbr", x => item.TransactionSetControlNbr   = x);
                            reader.TryGetString("TransactionSetPurposeCode", x => item.TransactionSetPurposeCode = x);
                            reader.TryGetString("TransactionNbr", x => item.TransactionNbr   = x);
                            reader.TryGetString("TransactionDate", x => item.TransactionDate = x);
                            reader.TryGetString("ReferenceNbr", x => item.ReferenceNbr       = x);
                            reader.TryGetString("ActionCode", x => item.ActionCode           = x);
                            reader.TryGetString("TdspDuns", x => item.TdspDuns                         = x);
                            reader.TryGetString("TdspName", x => item.TdspName                         = x);
                            reader.TryGetString("CrDuns", x => item.CrDuns                             = x);
                            reader.TryGetString("CrName", x => item.CrName                             = x);
                            reader.TryGetDateTime("ProcessDate", x => item.ProcessDate                 = x);
                            reader.TryGetInt32("TransactionTypeID", x => item.TransactionTypeId        = x);
                            reader.TryGetInt32("MarketID", x => item.MarketId                          = x);
                            reader.TryGetInt32("ProviderID", x => item.ProviderId                      = x);
                            reader.TryGetString("TransactionTime", x => item.TransactionTime           = x);
                            reader.TryGetString("TransactionTimeCode", x => item.TransactionTimeCode   = x);
                            reader.TryGetString("TransactionQualifier", x => item.TransactionQualifier = x);
                            collection.Add(item);
                        }

                        return(collection.ToArray());
                    }
                }
        }
Ejemplo n.º 13
0
        public void When_Saving_Header_With_No_Services_Then_Insert_Service_Is_Not_Called()
        {
            // arrange
            var header = new Type814Header();

            dataAccess.Stub(x => x.InsertHeader(Arg.Is(header)))
            .Return(1);

            // act
            concern.SaveHeader(header);

            // assert
            dataAccess.AssertWasNotCalled(x => x.InsertService(null), x => x.IgnoreArguments());
        }
Ejemplo n.º 14
0
        public void When_Saving_Header_Then_Insert_Header_Is_Called()
        {
            // arrange
            var header = new Type814Header();

            dataAccess.Expect(x => x.InsertHeader(Arg.Is(header)))
            .Return(1);

            // act
            concern.SaveHeader(header);

            // assert
            dataAccess.VerifyAllExpectations();
        }
Ejemplo n.º 15
0
        public void When_Saving_Header_With_Multiple_Service_Meter_Changes_Then_Insert_Service_Meter_Change_Is_Called_For_Each_Service_Meter_Change()
        {
            // arrange
            const int serviceMeterKey = 2;

            var meter = new Type814ServiceMeter();

            meter.AddChange(new Type814ServiceMeterChange {
                ChangeReason = "mock_one"
            });
            meter.AddChange(new Type814ServiceMeterChange {
                ChangeReason = "mock_two"
            });
            meter.AddChange(new Type814ServiceMeterChange {
                ChangeReason = "mock_six"
            });
            meter.AddChange(new Type814ServiceMeterChange {
                ChangeReason = "mock_ten"
            });

            var service = new Type814Service();

            service.AddMeter(meter);

            var header = new Type814Header();

            header.AddService(service);

            dataAccess.Stub(x => x.InsertHeader(Arg.Is(header)))
            .Return(1);

            dataAccess.Stub(x => x.InsertService(Arg.Is(service)))
            .Return(1);

            dataAccess.Stub(x => x.InsertServiceMeter(Arg.Is(meter)))
            .Return(serviceMeterKey);

            dataAccess.Expect(x => x.InsertServiceMeterChange(Arg <Type814ServiceMeterChange> .Is.TypeOf))
            .Return(1);

            // act
            concern.SaveHeader(header);

            // assert
            Assert.IsTrue(meter.Changes.All(x => x.MeterKey.Equals(serviceMeterKey)));

            dataAccess.AssertWasCalled(x => x.InsertServiceMeterChange(null), x => x.IgnoreArguments().Repeat.Times(4, 4));
            dataAccess.VerifyAllExpectations();
        }
Ejemplo n.º 16
0
        public void WriteService(Prism814Context context, Type814Header header, Type814Service[] services)
        {
            if (context.Market == MarketOptions.Maryland)
            {
                WriteServiceByMaintenanceTypeCode(context, header, services);
                return;
            }

            var actionCode = context.ActionCode.TrimStart('0');

            switch (actionCode)
            {
            case "7":
            case "10":
            case "19":
            case "24":
                WriteServiceDrop(context, header, services);
                break;

            case "8":
            case "9":
                WriteServiceReinstatement(context, header, services);
                break;

            case "12":
            case "13":
            case "21":
            case "PC":
                WriteServiceChange(context, header, services);
                break;

            case "PD":
                WriteServiceChangeResponse(context, header, services);
                break;

            case "18":
                WriteServiceEnrollment(context, header, services);
                WriteServiceDrop(context, header, services);
                break;

            case "":
                return;

            default:
                WriteServiceEnrollment(context, header, services);
                break;
            }
        }
Ejemplo n.º 17
0
        public int InsertHeader(Type814Header model)
        {
            using (var connection = new SqlConnection(connectionString))
                using (var command = connection.CreateCommand("csp814HeaderInsert"))
                {
                    SqlParameter keyParameter;

                    command.AddWithValue("@MarketFileId", model.MarketFileId)
                    .AddWithValue("@TransactionSetId", model.TransactionSetId)
                    .AddWithValue("@TransactionSetControlNbr", model.TransactionSetControlNbr)
                    .AddIfNotEmptyOrDbNull("@TransactionSetPurposeCode", model.TransactionSetPurposeCode)
                    .AddIfNotEmptyOrDbNull("@TransactionNbr", model.TransactionNbr)
                    .AddIfNotEmptyOrDbNull("@TransactionDate", model.TransactionDate)
                    .AddIfNotEmptyOrDbNull("@ReferenceNbr", model.ReferenceNbr)
                    .AddIfNotEmptyOrDbNull("@ActionCode", model.ActionCode)
                    .AddIfNotEmptyOrDbNull("@TdspDuns", model.TdspDuns)
                    .AddIfNotEmptyOrDbNull("@TdspName", model.TdspName)
                    .AddIfNotEmptyOrDbNull("@CrDuns", model.CrDuns)
                    .AddIfNotEmptyOrDbNull("@CrName", model.CrName)
                    .AddWithValue("@Direction", true)
                    .AddWithValue("@TransactionTypeID", model.TransactionTypeId)
                    .AddWithValue("@MarketID", model.MarketId)
                    .AddWithValue("@ProviderID", model.ProviderId)
                    .AddWithValue("@TransactionTime", model.TransactionTime)
                    .AddWithValue("@TransactionTimeCode", model.TransactionTimeCode)
                    .AddWithValue("@TransactionQualifier", model.TransactionQualifier)
                    .AddWithValue("@TransactionQueueTypeID", model.TransactionQueueTypeId)
                    .AddOutParameter("@Key", SqlDbType.Int, out keyParameter);

                    if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                    }

                    command.ExecuteNonQuery();

                    if (keyParameter.Value == null)
                    {
                        throw new Exception();
                    }

                    var headerKey = (int)keyParameter.Value;
                    model.HeaderKey = headerKey;

                    return(headerKey);
                }
        }
Ejemplo n.º 18
0
        public void When_Saving_Header_With_Multiple_Service_Meter_TOUs_Then_Insert_Service_Meter_Tou_Is_Called_For_Each_Service_Meter_TOU()
        {
            // arrange
            const int serviceMeterKey = 2;

            var meter = new Type814ServiceMeter();

            meter.AddTou(new Type814ServiceMeterTou {
                TouCode = "mock_here"
            });
            meter.AddTou(new Type814ServiceMeterTou {
                TouCode = "mock_now"
            });

            var service = new Type814Service();

            service.AddMeter(meter);

            var header = new Type814Header();

            header.AddService(service);

            dataAccess.Stub(x => x.InsertHeader(Arg.Is(header)))
            .Return(1);

            dataAccess.Stub(x => x.InsertService(Arg.Is(service)))
            .Return(1);

            dataAccess.Stub(x => x.InsertServiceMeter(Arg.Is(meter)))
            .Return(serviceMeterKey);

            dataAccess.Expect(x => x.InsertServiceMeterTou(Arg <Type814ServiceMeterTou> .Is.TypeOf))
            .Return(1);

            // act
            concern.SaveHeader(header);

            // assert
            Assert.IsTrue(meter.Tous.All(x => x.MeterKey.Equals(serviceMeterKey)));

            dataAccess.AssertWasCalled(x => x.InsertServiceMeterTou(null), x => x.IgnoreArguments().Repeat.Times(2, 2));
            dataAccess.VerifyAllExpectations();
        }
Ejemplo n.º 19
0
        public void WriteHeader(XContainer container, Type814Header header)
        {
            if (header == null)
            {
                return;
            }

            if (!header.HeaderKey.HasValue)
            {
                return;
            }

            var headerKey = header.HeaderKey.Value;
            var element   = new XElement("Header",
                                         new XElement("HeaderKey", headerKey));

            element.TryAddElement("TransactionSetId", header.TransactionSetId);
            element.TryAddElement("TransactionSetControlNbr", header.TransactionSetControlNbr);
            element.TryAddElement("TransactionSetPurposeCode", header.TransactionSetPurposeCode);
            element.TryAddElement("TransactionNbr", header.TransactionNbr);
            element.TryAddElement("TransactionDate", header.TransactionDate);
            element.TryAddElement("TransactionTime", header.TransactionTime);
            element.TryAddElement("TransactionTimeCode", header.TransactionTimeCode);
            element.TryAddElement("ReferenceNbr", header.ReferenceNbr);
            element.TryAddElement("ActionCode", header.ActionCode);
            element.TryAddElement("TdspDuns", header.TdspDuns);
            element.TryAddElement("TdspName", header.TdspName);
            element.TryAddElement("CrDuns", header.CrDuns);
            element.TryAddElement("CrName", header.CrName);
            element.TryAddElement("SegmentCount", "0");
            element.TryAddElement("TransactionQualifier", header.TransactionQualifier);
            container.Add(element);
            logger.TraceFormat("Added 814 \"Header\" XML element for Header {0}", headerKey);

            var names = exportDataAccess.ListNames(headerKey);

            WriteName(element, names);

            var services = exportDataAccess.ListServices(headerKey);

            WriteService(element, services);
        }
Ejemplo n.º 20
0
        public void WriteAccount(Prism814Context context, Type814Header header)
        {
            var ercotName        = string.Empty;
            var ercotDuns        = string.Empty;
            var transactionSetId = string.Empty;
            var stateId          = context.TradingPartnerId.Substring(3, 2);

            if (context.Market == MarketOptions.Texas)
            {
                ercotName = "ERCOT";
                ercotDuns = "183529049";
            }

            var actionCode = context.ActionCode;

            if (context.Market == MarketOptions.Texas)
            {
                transactionSetId = (actionCode.StartsWith("0"))
                                       ? actionCode.Substring(1)
                                       : actionCode;
            }

            var line = string.Format("01|{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}||{9}|||||{10}|{11}|{12}|",
                                     context.TradingPartnerId,
                                     stateId,
                                     header.TransactionSetPurposeCode,
                                     header.TransactionNbr,
                                     header.ReferenceNbr,
                                     header.TdspDuns,
                                     header.TdspName.ToUpper(),
                                     header.CrDuns,
                                     header.CrName.ToUpper(),
                                     header.TransactionDate,
                                     transactionSetId,
                                     ercotName,
                                     ercotDuns);

            context.AppendLine(line);
            logger.TraceFormat("Wrote 814 \"01\" PRISM line for Header {0}", header.HeaderKey);
        }
Ejemplo n.º 21
0
        public void When_Saving_Header_With_Multiple_Service_Statuses_Then_Insert_Service_Status_Is_Called_For_Each_Service_Status()
        {
            // arrange
            const int serviceKey = 2;

            var service = new Type814Service();

            service.AddStatus(new Type814ServiceStatus {
                StatusCode = "mock_one"
            });
            service.AddStatus(new Type814ServiceStatus {
                StatusCode = "mock_two"
            });
            service.AddStatus(new Type814ServiceStatus {
                StatusCode = "mock_three"
            });

            var header = new Type814Header();

            header.AddService(service);

            dataAccess.Stub(x => x.InsertHeader(Arg.Is(header)))
            .Return(1);

            dataAccess.Stub(x => x.InsertService(Arg.Is(service)))
            .Return(serviceKey);

            dataAccess.Expect(x => x.InsertServiceStatus(Arg <Type814ServiceStatus> .Is.TypeOf))
            .Return(1);

            // act
            concern.SaveHeader(header);

            // assert
            Assert.IsTrue(service.Statuses.All(x => x.ServiceKey.Equals(serviceKey)));

            dataAccess.AssertWasCalled(x => x.InsertServiceStatus(null), x => x.IgnoreArguments().Repeat.Times(3, 3));
            dataAccess.VerifyAllExpectations();
        }
Ejemplo n.º 22
0
        public void ParseHeader(Prism814Context context, string[] marketFields)
        {
            var model = new Type814Header
            {
                TransactionSetPurposeCode = "11",
                TransactionSetId          = marketFields.AtIndex(16),
                TransactionNbr            = marketFields.AtIndex(4),
                TransactionDate           = marketFields.AtIndex(11),
                ReferenceNbr = marketFields.AtIndex(5),
                TdspDuns     = marketFields.AtIndex(6),
                TdspName     = marketFields.AtIndex(7),
                CrDuns       = marketFields.AtIndex(8),
                CrName       = marketFields.AtIndex(9),
            };

            marketFields.TryAtIndex(3, x => model.TransactionSetPurposeCode = x);

            var identifiedMarket = clientDataAccess.IdentifyMarket(model.TdspDuns);

            if (identifiedMarket.HasValue)
            {
                context.SetMarket(identifiedMarket.Value);
            }
            else
            {
                context.SetMarket((int)MarketOptions.Texas);
            }

            model.MarketId   = context.MarketId;
            model.ProviderId = 1;

            model.ActionCode = context.Alias;
            if (context.Market == MarketOptions.Texas)
            {
                model.ActionCode = marketFields.AtIndex(16);
            }

            context.PushModel(model);
        }
Ejemplo n.º 23
0
 public void AddHeader(Type814Header item)
 {
     headers.Add(item);
 }
Ejemplo n.º 24
0
        private List <string> GetNameLines(Type814Header header)
        {
            var nameLines = new List <string>();

            var nameLevelColumns = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20}",
                                                 "BillingEntityName",
                                                 "BillingAddress1",
                                                 "BillingAddress2",
                                                 "BillingCity",
                                                 "BillingState",
                                                 "BillingPostalCode",
                                                 "BillingContactName",
                                                 "BillingContactPhoneNumber1",
                                                 "BillingEntityFirstName",
                                                 "BillingEntityLastName",
                                                 "ServiceCustType",
                                                 "ServiceEntityName",
                                                 "ServiceAddress1",
                                                 "ServiceAddress2",
                                                 "ServiceCity",
                                                 "ServiceState",
                                                 "ServicePostalCode",
                                                 "ServiceContactName",
                                                 "ServiceContactPhoneNumber1",
                                                 "ServiceEntityFirstName",
                                                 "ServiceEntityLastName");

            nameLines.Add(nameLevelColumns);


            var billingName      = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", "", "", "", "", "", "", "", "", "", "");
            var serviceName      = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}", "", "", "", "", "", "", "", "", "", "", "");
            var serviceNameFound = false;
            var billingNameFound = false;


            if (header.HeaderKey.HasValue)
            {
                //we have to load the Names here
                var names = exportDataAccess.ListNames(header.HeaderKey.Value);



                //Loop for Names
                foreach (var name in names)
                {
                    if (name.EntityIdType.ToUpper() == "8R" && !serviceNameFound)
                    {
                        serviceName = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}",
                                                    name.CustType,
                                                    name.EntityName,
                                                    name.Address1,
                                                    name.Address2,
                                                    name.City,
                                                    name.State,
                                                    name.PostalCode,
                                                    name.ContactName,
                                                    name.ContactPhoneNbr1,
                                                    name.EntityFirstName,
                                                    name.EntityLastName
                                                    );

                        serviceNameFound = true;
                    }


                    if (GetBillingAddressEntityIdTypes(header.ActionCode).Any(match => name.EntityIdType.ToUpper() == match && !billingNameFound))
                    {
                        billingName = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}",
                                                    name.EntityName,
                                                    name.Address1,
                                                    name.Address2,
                                                    name.City,
                                                    name.State,
                                                    name.PostalCode,
                                                    name.ContactName,
                                                    name.ContactPhoneNbr1,
                                                    name.EntityFirstName,
                                                    name.EntityLastName);


                        billingNameFound = true;
                    }


                    if (!serviceNameFound || !billingNameFound)
                    {
                        continue;
                    }

                    break;
                }//end of name loop
            }


            var nameLevelData = string.Format("{0},{1}", billingName, serviceName);

            nameLines.Add(nameLevelData);


            return(nameLines);
        }
Ejemplo n.º 25
0
        public void WriteServiceDrop(Prism814Context context, Type814Header header, Type814Service[] services)
        {
            var actionCode = context.ActionCode.TrimStart('0');

            foreach (var service in services)
            {
                if (!service.ServiceKey.HasValue)
                {
                    continue;
                }

                var serviceKey         = service.ServiceKey.Value;
                var lineTrackingNumber = "1";
                var crDuns             = string.Empty;
                var dropCode           = string.Empty;
                var specialNeedsFlag   = string.Empty;

                if (context.Market != MarketOptions.Texas)
                {
                    lineTrackingNumber = serviceKey.ToString();
                }
                if (actionCode.Equals("29"))
                {
                    dropCode = "09";
                }
                if (actionCode.Equals("10"))
                {
                    specialNeedsFlag = service.SpecialNeedsIndicator;
                }

                var membershipId      = IdentifyLdcAccountNumber(context, service);
                var premiseNumber     = IdentifyEsiId(context, service);
                var serviceActionCode = service.ActionCode;

                switch (actionCode)
                {
                case "18":
                    if (!service.MaintenanceTypeCode.Equals("002"))
                    {
                        return;
                    }
                    break;

                case "D":
                    dropCode = "P";
                    break;
                }

                if (context.Market == MarketOptions.Maryland)
                {
                    crDuns = header.CrDuns;
                    if (serviceActionCode.Equals("Q", StringComparison.Ordinal))
                    {
                        serviceActionCode = string.Empty;
                    }
                }

                var line =
                    string.Format(
                        "10|{0}|{1}|{2}|{3}|{4}|D|{5}|{6}|{7}|||{12}||||||||||||||||||{8}|||||||{9}||||||{10}|||{11}||||||||{14}||||{13}|",
                        context.TradingPartnerId, service.ServiceType1, service.ServiceType2, service.ServiceType3,
                        lineTrackingNumber, serviceActionCode, dropCode, membershipId, service.BillType, service.CsaFlag,
                        premiseNumber, service.EnergizedFlag, crDuns, service.MeterAccessNote, specialNeedsFlag);

                context.AppendLine(line);
                logger.TraceFormat("Wrote 814 \"10\" PRISM line for Header {0}", header.HeaderKey);

                if (actionCode.Equals("10") || actionCode.Equals("24"))
                {
                    WriteServiceDate(context, service);
                }

                WriteServiceReject(context, service);
                WriteServiceStatus(context, service);

                if (actionCode.Equals("7") || actionCode.Equals("19"))
                {
                    continue;
                }

                WriteServiceMeter(context, service);
            }
        }
Ejemplo n.º 26
0
        private List <string> GetServiceLines(Type814Header header)
        {
            var serviceLines = new List <string>();

            var serviceLevelColumns = string.Format("{0},{1},{2}",
                                                    "ServiceType1",
                                                    "EsiId",
                                                    "ESPAccountNumber");

            var meterLevelColumns = string.Format("{0}",
                                                  "MeterNumber");

            //Add column headers
            serviceLines.Add(string.Format("{0},{1}", serviceLevelColumns, meterLevelColumns));


            Type814Service[] services = null;

            if (header.HeaderKey.HasValue)
            {
                services = exportDataAccess.ListServices(header.HeaderKey.Value);
            }

            //if there are no services then use blank lines
            //even if services are not there we need to enter empty columns to maintain tabular format for csv
            if (services == null || services.Length == 0)
            {
                var serviceLevelEmpty = string.Format("{0},{1},{2}",
                                                      string.Empty, string.Empty, string.Empty);

                var meterLevelEmpty = string.Format("{0}",
                                                    string.Empty);



                //Add headers
                serviceLines.Add(string.Format("{0},{1}", serviceLevelEmpty, meterLevelEmpty));
            }


            if (services != null)
            {
                //loop for Service
                foreach (var service in services)
                {
                    var serviceLevelData = string.Format("{0},{1},{2}",
                                                         service.ServiceType1,
                                                         service.EsiId,
                                                         service.EspAccountNumber);


                    Type814ServiceMeter[] meters = null;

                    if (service.ServiceKey.HasValue)
                    {
                        meters = exportDataAccess.ListServiceMeters(service.ServiceKey.Value);
                    }

                    //even if meters are not there we need to enter empty columns to maintain tabular format for csv
                    if (meters == null || meters.Length == 0)
                    {
                        var meterEmpty = string.Format("{0}",
                                                       string.Empty);

                        //Add ServiceData with EmptyMeterData
                        serviceLines.Add(string.Format("{0},{1}", serviceLevelData, meterEmpty));
                    }

                    if (meters == null)
                    {
                        continue;
                    }

                    //inner loop for meters
                    foreach (var meter in meters)
                    {
                        var meterLevelData = string.Format("{0}",
                                                           meter.MeterNumber);

                        //Add ServiceData with MeterData
                        serviceLines.Add(string.Format("{0},{1}", serviceLevelData, meterLevelData));
                    } //inner loop for meters in service
                }     //end of service loop
            }

            return(serviceLines);
        }
Ejemplo n.º 27
0
        public void WriteServiceEnrollment(Prism814Context context, Type814Header header, Type814Service[] services)
        {
            var actionCode = context.ActionCode.TrimStart('0');

            foreach (var service in services)
            {
                if (!service.ServiceKey.HasValue)
                {
                    continue;
                }

                var serviceKey         = service.ServiceKey.Value;
                var lineTrackingNumber = "1";
                var specialNeedsFlag   = string.Empty;

                if (context.Market != MarketOptions.Texas)
                {
                    lineTrackingNumber = serviceKey.ToString();
                }
                if (actionCode.Equals("1") || actionCode.Equals("16"))
                {
                    specialNeedsFlag = service.SpecialNeedsIndicator;
                }

                var membershipId               = IdentifyLdcAccountNumber(context, service);
                var premiseNumber              = IdentifyEsiId(context, service);
                var serviceActionCode          = string.Empty;
                var serviceTransactionTypeCode = string.Empty;

                switch (actionCode)
                {
                case "15":
                    serviceActionCode          = service.ActionCode;
                    serviceTransactionTypeCode = service.MaintenanceTypeCode;
                    break;

                case "18":
                    if (!service.MaintenanceTypeCode.Equals("021"))
                    {
                        return;
                    }
                    serviceActionCode = service.ActionCode;
                    break;

                case "29":
                    serviceActionCode          = service.ActionCode;
                    serviceTransactionTypeCode = service.MaintenanceTypeCode;
                    break;

                case "26":
                    if (context.Market == MarketOptions.Texas)
                    {
                        membershipId = string.Empty;
                    }
                    break;

                default:
                    serviceActionCode = service.ActionCode;
                    break;
                }

                var priorityCode = service.PriorityCode;
                if (priorityCode.Length >= 2)
                {
                    priorityCode = priorityCode.Substring(0, 2);
                }

                if (context.Market != MarketOptions.Texas)
                {
                    serviceActionCode = string.Empty;
                }

                var line =
                    string.Format(
                        "10|{0}|{1}|{2}|{3}|{4}|E|{5}|{6}|{7}|||||||||||||{8}||||||||{9}|{10}|||||||||||{11}|{12}||{13}|||||||||{15}||||{14}|||||||||||",
                        context.TradingPartnerId, service.ServiceType1, service.ServiceType2, service.ServiceType3,
                        lineTrackingNumber, serviceActionCode, serviceTransactionTypeCode, membershipId,
                        service.NotificationWaiver, service.BillType, service.BillCalculator, service.ServiceType4,
                        premiseNumber, priorityCode, service.MeterAccessNote, specialNeedsFlag);

                context.AppendLine(line);
                logger.TraceFormat("Wrote 814 \"10\" PRISM line for Header {0}", header.HeaderKey);

                if (!actionCode.Equals("23") && !actionCode.Equals("29"))
                {
                    if (service.ServiceType3.Equals("SW", StringComparison.Ordinal) ||
                        service.ServiceType3.Equals("MVI", StringComparison.Ordinal))
                    {
                        WriteServiceDate(context, service);
                    }
                }

                if (context.Market == MarketOptions.Maryland && actionCode.Equals("E"))
                {
                    WriteServiceDate(context, service);
                    WriteServiceRateData(context, service);
                }

                if (actionCode.Equals("29") || actionCode.Equals("15"))
                {
                    if (serviceActionCode.Equals("R", StringComparison.Ordinal))
                    {
                        WriteServiceReject(context, service);
                    }
                }

                if (!actionCode.Equals("18") && !actionCode.Equals("21") && !actionCode.Equals("23") && !actionCode.Equals("26") && !actionCode.Equals("29"))
                {
                    WriteServiceMeter(context, service);
                }
            }
        }
Ejemplo n.º 28
0
 public void SaveHeader(Type814Header header, int marketFileId)
 {
     header.MarketFileId = marketFileId;
     SaveHeader(header);
 }
Ejemplo n.º 29
0
        public void SaveHeader(Type814Header header)
        {
            logger.Trace("Start inserting header.");

            var headerKey = marketDataAccess.InsertHeader(header);

            logger.DebugFormat("Inserted Header \"{0}\".", headerKey);

            foreach (var name in header.Names)
            {
                name.HeaderKey = headerKey;
                var nameKey = marketDataAccess.InsertName(name);
                logger.DebugFormat("Inserted Name \"{0}\" for Header \"{1}\".", nameKey, headerKey);
            }

            foreach (var service in header.Services)
            {
                service.HeaderKey = headerKey;
                var serviceKey = marketDataAccess.InsertService(service);
                logger.DebugFormat("Inserted Service \"{0}\" for Header \"{1}\".", serviceKey, headerKey);

                foreach (var serviceAccountChange in service.Changes)
                {
                    serviceAccountChange.ServiceKey = serviceKey;
                    var serviceAccountChangeKey = marketDataAccess.InsertServiceAccountChange(serviceAccountChange);
                    logger.DebugFormat("Inserted Service Account Change \"{0}\" for Service \"{1}\".",
                                       serviceAccountChangeKey, serviceKey);
                }

                foreach (var serviceDate in service.Dates)
                {
                    serviceDate.ServiceKey = serviceKey;
                    var serviceDateKey = marketDataAccess.InsertServiceDate(serviceDate);
                    logger.DebugFormat("Inserted Service Date \"{0}\" for Service \"{1}\".", serviceDateKey, serviceKey);
                }

                foreach (var serviceMeter in service.Meters)
                {
                    serviceMeter.ServiceKey = serviceKey;
                    var serviceMeterKey = marketDataAccess.InsertServiceMeter(serviceMeter);
                    logger.DebugFormat("Inserted Service Meter \"{0}\" for Service \"{1}\".", serviceMeterKey, serviceKey);

                    foreach (var serviceMeterChange in serviceMeter.Changes)
                    {
                        serviceMeterChange.MeterKey = serviceMeterKey;
                        var meterChangeKey = marketDataAccess.InsertServiceMeterChange(serviceMeterChange);
                        logger.DebugFormat("Inserted Service Meter Change \"{0}\" for Service Meter \"{1}\".",
                                           meterChangeKey, serviceMeterKey);
                    }

                    foreach (var serviceMeterTou in serviceMeter.Tous)
                    {
                        serviceMeterTou.MeterKey = serviceMeterKey;
                        var meterTouKey = marketDataAccess.InsertServiceMeterTou(serviceMeterTou);
                        logger.DebugFormat("Inserted Service Meter TOU \"{0}\" for Service Meter \"{1}\".",
                                           meterTouKey, serviceMeterKey);
                    }

                    foreach (var serviceMeterType in serviceMeter.Types)
                    {
                        serviceMeterType.MeterKey = serviceMeterKey;
                        var meterTypeKey = marketDataAccess.InsertServiceMeterType(serviceMeterType);
                        logger.DebugFormat("Inserted Service Meter Type \"{0}\" for Service Meter \"{1}\".",
                                           meterTypeKey, serviceMeterKey);
                    }
                }

                foreach (var serviceReject in service.Rejects)
                {
                    serviceReject.ServiceKey = serviceKey;
                    var serviceRejectKey = marketDataAccess.InsertServiceReject(serviceReject);
                    logger.DebugFormat("Inserted Service Reject \"{0}\" for Service \"{1}\".", serviceRejectKey,
                                       serviceKey);
                }

                foreach (var serviceStatus in service.Statuses)
                {
                    serviceStatus.ServiceKey = serviceKey;
                    var serviceStatusKey = marketDataAccess.InsertServiceStatus(serviceStatus);
                    logger.DebugFormat("Inserted Service Reject \"{0}\" for Service \"{1}\".", serviceStatusKey,
                                       serviceKey);
                }
            }

            logger.Trace("Completed inserting header.");
        }
Ejemplo n.º 30
0
        public void Should_Produce_The_Same_Content_As_A_Sample_File()
        {
            const string expectedContent =
                @"SH|SELTX183529049ENR|2276133|D|O|
01|SELTX183529049ENR|TX|Q|2276133||957877905|CENTERPOINT ENERGY|148055531|STARTEX POWER||20130309|||||24|ERCOT|183529049|
05|SELTX183529049ENR|8R|COTTONWOOD CAPITAL PROPERTY MANAGEMENT II LLC AS AGENT FOR T||||12700 STAFFORD RD BS2||STAFFORD|TX|77477|||2815648277|2815648277|FRANK MILLER||||||
10|SELTX183529049ENR|EL|CE|MVO|1|D|||||||||||||||||||||||||||||||||||||1008901023817063480105||||||||||||||||
11|SELTX183529049ENR|||||||||||||||20130312||||
TL|1";

            // arrange
            var port = new CspDunsPortModel
            {
                CspDunsId        = 1,
                CspDunsPortId    = 1,
                Duns             = "148055531",
                LdcDuns          = string.Empty,
                LdcShortName     = string.Empty,
                TradingPartnerId = "SELTX{DUNS}",
                ProviderId       = 1,
                FileType         = string.Empty,
            };

            var header = new Type814Header
            {
                HeaderKey = 3893482,
                TransactionSetPurposeCode = "Q",
                TransactionNbr            = "2276133",
                TransactionDate           = "20130309",
                ActionCode             = "24",
                TdspDuns               = "957877905",
                TdspName               = "Centerpoint Energy",
                CrDuns                 = "148055531",
                CrName                 = "StarTex Power",
                TransactionTypeId      = 13,
                MarketId               = 1,
                ProviderId             = 1,
                TransactionQueueTypeId = 1,
                ReferenceNbr           = string.Empty,
            };

            var name = new Type814Name
            {
                HeaderKey        = 3893482,
                NameKey          = 2470182,
                EntityIdType     = "8R",
                EntityName       = "COTTONWOOD CAPITAL PROPERTY MANAGEMENT II LLC AS AGENT FOR T",
                EntityName2      = string.Empty,
                EntityName3      = string.Empty,
                Address1         = "12700 STAFFORD RD BS2",
                Address2         = string.Empty,
                City             = "STAFFORD",
                State            = "TX",
                PostalCode       = "77477",
                ContactName      = "FRANK MILLER",
                ContactPhoneNbr1 = "281-564-8277",
                ContactPhoneNbr2 = string.Empty,
                EntityFirstName  = string.Empty,
                EntityLastName   = "Cottonwood Capital Property Management II LLC as ",
                EntityEmail      = string.Empty,
            };

            var service = new Type814Service
            {
                HeaderKey           = 3893482,
                ServiceKey          = 3892992,
                ServiceTypeCode1    = "SH",
                ServiceType1        = "EL",
                ServiceTypeCode2    = "SH",
                ServiceType2        = "CE",
                ServiceTypeCode3    = "SH",
                ServiceType3        = "MVO",
                MaintenanceTypeCode = "002",
                EsiId = "1008901023817063480105",
                SpecialNeedsIndicator = "N",
                SpecialReadSwitchDate = "20130312",
                EspAccountNumber      = "291920",
                PaymentOption         = "N",
            };

            clientDataAccess.Expect(x => x.ListCspDunsPort())
            .Return(new[] { port });

            clientDataAccess.Expect(x => x.IdentifyMarket(Arg <string> .Is.Anything))
            .Return(1);

            exportDataAccess.Expect(x => x.ListUnprocessed(Arg <string> .Is.Anything, Arg <string> .Is.Anything, Arg.Is(1)))
            .Return(new[] { header });

            exportDataAccess.Expect(x => x.ListNames(Arg <int> .Is.Anything))
            .Return(new[] { name });

            exportDataAccess.Expect(x => x.ListServices(Arg <int> .Is.Anything))
            .Return(new[] { service });

            exportDataAccess.Stub(x => x.ListServiceStatuses(Arg <int> .Is.Anything))
            .Return(new Type814ServiceStatus[0]);

            exportDataAccess.Stub(x => x.ListServiceRejects(Arg <int> .Is.Anything))
            .Return(new Type814ServiceReject[0]);

            exportDataAccess.Stub(x => x.ListServiceMeters(Arg <int> .Is.Anything))
            .Return(new Type814ServiceMeter[0]);

            // act
            var results = concern.Export(CancellationToken.None);

            // assert
            Assert.IsNotNull(results);
            Assert.AreEqual(1, results.Length);

            var result = results[0];

            Assert.IsNotNull(result);

            Assert.AreEqual(1, result.HeaderCount);
            CollectionAssert.Contains(result.HeaderKeys, 3893482);

            result.FinalizeDocument(1);
            Assert.AreEqual(expectedContent, result.Content);
        }