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()); }
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(); }
public void ParseServiceMeter(Prism814Context context, string[] marketFields) { var current = context.Current; if (current == null || current.ModelType != Type814Types.Service) { throw new InvalidOperationException(); } var service = current as Type814Service; if (service == null) { throw new InvalidOperationException(); } var model = new Type814ServiceMeter { EntityIdCode = marketFields.AtIndex(4), MeterNumber = marketFields.AtIndex(2), MeterType = marketFields.AtIndex(5), LoadProfile = marketFields.AtIndex(8), RateClass = marketFields.AtIndex(6), RateSubClass = marketFields.AtIndex(7), MeterCycle = marketFields.AtIndex(10), MeterCycleDayOfMonth = marketFields.AtIndex(36), SpecialNeedsIndicator = marketFields.AtIndex(21), OldMeterNumber = marketFields.AtIndex(3), MeterOwnerIndicator = marketFields.AtIndex(23), AmsIndicator = marketFields.AtIndex(51), SummaryInterval = marketFields.AtIndex(51), }; service.AddMeter(model); context.PushModel(model); marketFields.TryAtIndex(11, x => context.ProductType = x); marketFields.TryAtIndex(13, x => context.UnmeterQuantity = x); marketFields.TryAtIndex(14, x => context.UnmeterDescription = x); var hasIntervalType = false; var hasProductType = false; marketFields.TryAtIndex(5, x => hasIntervalType = true); marketFields.TryAtIndex(11, x => hasProductType = true); if (hasIntervalType || !hasProductType) { return; } var meterTypeModel = new Type814ServiceMeterType { ProductType = marketFields.AtIndex(11), UnmeteredNumberOfDevices = marketFields.AtIndex(13), UnmeteredDescription = marketFields.AtIndex(37), }; model.AddType(meterTypeModel); }
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(); }
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(); }
public Type814ServiceMeter[] ListServiceMeters(int serviceKey) { using (var connection = new SqlConnection(connectionString)) using (var command = connection.CreateCommand("esp_814ServiceMeterList")) { command.AddWithValue("@Service_Key", serviceKey); if (connection.State != ConnectionState.Open) { connection.Open(); } var collection = new List <Type814ServiceMeter>(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var item = new Type814ServiceMeter { MeterKey = reader.GetInt32("Meter_Key"), ServiceKey = serviceKey, }; reader.TryGetString("EntityIdCode", x => item.EntityIdCode = x); reader.TryGetString("MeterNumber", x => item.MeterNumber = x); reader.TryGetString("MeterCode", x => item.MeterCode = x); reader.TryGetString("MeterType", x => item.MeterType = x); reader.TryGetString("LoadProfile", x => item.LoadProfile = x); reader.TryGetString("RateClass", x => item.RateClass = x); reader.TryGetString("RateSubClass", x => item.RateSubClass = x); reader.TryGetString("MeterCycle", x => item.MeterCycle = x); reader.TryGetString("MeterCycleDayOfMonth", x => item.MeterCycleDayOfMonth = x); reader.TryGetString("SpecialneedsIndicator", x => item.SpecialNeedsIndicator = x); reader.TryGetString("OldMeterNumber", x => item.OldMeterNumber = x); reader.TryGetString("MeterOwnerIndicator", x => item.MeterOwnerIndicator = x); reader.TryGetString("EntityType", x => item.EntityType = x); reader.TryGetString("TimeOFUse", x => item.TimeOfUse = x); reader.TryGetString("ESPRateCode", x => item.EspRateCode = x); reader.TryGetString("OrganizationName", x => item.OrganizationName = x); reader.TryGetString("FirstName", x => item.FirstName = x); reader.TryGetString("MiddleName", x => item.MiddleName = x); reader.TryGetString("NamePrefix", x => item.NamePrefix = x); reader.TryGetString("NameSuffix", x => item.NameSuffix = x); reader.TryGetString("IdentificationCode", x => item.IdentificationCode = x); reader.TryGetString("EntityName2", x => item.EntityName2 = x); reader.TryGetString("EntityName3", x => item.EntityName3 = x); reader.TryGetString("Address1", x => item.Address1 = x); reader.TryGetString("Address2", x => item.Address2 = x); reader.TryGetString("City", x => item.City = x); reader.TryGetString("State", x => item.State = x); reader.TryGetString("Zip", x => item.Zip = x); reader.TryGetString("CountryCode", x => item.CountryCode = x); reader.TryGetString("County", x => item.County = x); reader.TryGetString("PlanNumber", x => item.PlanNumber = x); reader.TryGetString("ServicesReferenceNumber", x => item.ServicesReferenceNumber = x); reader.TryGetString("AffiliationNumber", x => item.AffiliationNumber = x); reader.TryGetString("CostElement", x => item.CostElement = x); reader.TryGetString("CoverageCode", x => item.CoverageCode = x); reader.TryGetString("LossReportNumber", x => item.LossReportNumber = x); reader.TryGetString("GeographicNumber", x => item.GeographicNumber = x); reader.TryGetString("ItemNumber", x => item.ItemNumber = x); reader.TryGetString("LocationNumber", x => item.LocationNumber = x); reader.TryGetString("PriceListNumber", x => item.PriceListNumber = x); reader.TryGetString("ProductType", x => item.ProductType = x); reader.TryGetString("QualityInspectionArea", x => item.QualityInspectionArea = x); reader.TryGetString("ShipperCarOrderNumber", x => item.ShipperCarOrderNumber = x); reader.TryGetString("StandardPointLocation", x => item.StandardPointLocation = x); reader.TryGetString("ReportIdentification", x => item.ReportIdentification = x); reader.TryGetString("Supplier", x => item.Supplier = x); reader.TryGetString("Area", x => item.Area = x); reader.TryGetString("CollectorIdentification", x => item.CollectorIdentification = x); reader.TryGetString("VendorAgentNumber", x => item.VendorAgentNumber = x); reader.TryGetString("VendorAbbreviation", x => item.VendorAbbreviation = x); reader.TryGetString("VendorIdNumber", x => item.VendorIdNumber = x); reader.TryGetString("VendorOrderNumber", x => item.VendorOrderNumber = x); reader.TryGetString("PricingStructureCode", x => item.PricingStructureCode = x); reader.TryGetString("MeterOwnerDUNS", x => item.MeterOwnerDuns = x); reader.TryGetString("MeterOwner", x => item.MeterOwner = x); reader.TryGetString("MeterInstallerDUNS", x => item.MeterInstallerDuns = x); reader.TryGetString("MeterInstaller", x => item.MeterInstaller = x); reader.TryGetString("MeterReaderDUNS", x => item.MeterReaderDuns = x); reader.TryGetString("MeterReader", x => item.MeterReader = x); reader.TryGetString("MeterMaintenanceProviderDUNS", x => item.MeterMaintenanceProviderDuns = x); reader.TryGetString("MeterMaintenanceProvider", x => item.MeterMaintenanceProvider = x); reader.TryGetString("MeterDataManagementAgentDUNS", x => item.MeterDataManagementAgentDuns = x); reader.TryGetString("MeterDataManagementAgent", x => item.MeterDataManagementAgent = x); reader.TryGetString("SchedulingCoordinatorDUNS", x => item.SchedulingCoordinatorDuns = x); reader.TryGetString("SchedulingCoordinator", x => item.SchedulingCoordinator = x); reader.TryGetString("PackageOption", x => item.PackageOption = x); reader.TryGetString("UsageCode", x => item.UsageCode = x); reader.TryGetString("MeterInstallPending", x => item.MeterInstallPending = x); reader.TryGetString("MeterServiceVoltage", x => item.MeterServiceVoltage = x); reader.TryGetString("LossFactor", x => item.LossFactor = x); reader.TryGetString("SummaryInterval", x => item.SummaryInterval = x); collection.Add(item); } return(collection.ToArray()); } } }
public int InsertServiceMeter(Type814ServiceMeter model) { using (var connection = new SqlConnection(connectionString)) using (var command = connection.CreateCommand("csp814ServiceMeterInsert")) { SqlParameter keyParameter; command.AddWithValue("@Service_Key", model.ServiceKey) .AddIfNotEmptyOrDbNull("@EntityIdCode", model.EntityIdCode) .AddIfNotEmptyOrDbNull("@MeterNumber", model.MeterNumber) .AddIfNotEmptyOrDbNull("@MeterCode", model.MeterCode) .AddIfNotEmptyOrDbNull("@MeterType", model.MeterType) .AddIfNotEmptyOrDbNull("@LoadProfile", model.LoadProfile) .AddIfNotEmptyOrDbNull("@RateClass", model.RateClass) .AddIfNotEmptyOrDbNull("@RateSubClass", model.RateSubClass) .AddIfNotEmptyOrDbNull("@MeterCycle", model.MeterCycle) .AddIfNotEmptyOrDbNull("@MeterCycleDayOfMonth", model.MeterCycleDayOfMonth) .AddIfNotEmptyOrDbNull("@SpecialNeedsIndicator", model.SpecialNeedsIndicator) .AddIfNotEmptyOrDbNull("@OldMeterNumber", model.OldMeterNumber) .AddWithValue("@MeterOwnerIndicator", model.MeterOwnerIndicator) .AddWithValue("@EntityType", model.EntityType) .AddWithValue("@TimeOFUse", model.TimeOfUse) .AddWithValue("@ESPRateCode", model.EspRateCode) .AddWithValue("@PricingStructureCode", model.PricingStructureCode) .AddWithValue("@MeterOwner", model.MeterOwner) .AddWithValue("@MeterOwnerDUNS", model.MeterOwnerDuns) .AddWithValue("@MeterInstaller", model.MeterInstaller) .AddWithValue("@MeterInstallerDUNS", model.MeterInstallerDuns) .AddWithValue("@MeterReader", model.MeterReader) .AddWithValue("@MeterReaderDUNS", model.MeterReaderDuns) .AddWithValue("@MeterMaintenanceProvider", model.MeterMaintenanceProvider) .AddWithValue("@MeterMaintenanceProviderDUNS", model.MeterMaintenanceProviderDuns) .AddWithValue("@MeterDataManagementAgent", model.MeterDataManagementAgent) .AddWithValue("@MeterDataManagementAgentDUNS", model.MeterDataManagementAgentDuns) .AddWithValue("@SchedulingCoordinator", model.SchedulingCoordinator) .AddWithValue("@SchedulingCoordinatorDUNS", model.SchedulingCoordinatorDuns) .AddWithValue("@MeterInstallPending", model.MeterInstallPending) .AddWithValue("@PackageOption", model.PackageOption) .AddWithValue("@UsageCode", model.UsageCode) .AddWithValue("@MeterServiceVoltage", model.MeterServiceVoltage) .AddWithValue("@SummaryInterval", model.SummaryInterval) .AddOutParameter("@Meter_Key", SqlDbType.Int, out keyParameter); if (connection.State != ConnectionState.Open) { connection.Open(); } command.ExecuteNonQuery(); if (keyParameter.Value == null) { throw new Exception(); } var meterKey = (int)keyParameter.Value; model.MeterKey = meterKey; return(meterKey); } }
public Type814ServiceMeter ParseServiceMeter(XElement element, IDictionary <string, XNamespace> namespaces) { XNamespace empty; if (!namespaces.TryGetValue(string.Empty, out empty)) { empty = XNamespace.None; } var model = new Type814ServiceMeter { EntityIdCode = element.GetChildText(empty + "EntityIdCode"), MeterNumber = element.GetChildText(empty + "MeterNumber"), MeterCode = element.GetChildText(empty + "MeterCode"), MeterType = element.GetChildText(empty + "MeterType"), LoadProfile = element.GetChildText(empty + "LoadProfile"), RateClass = element.GetChildText(empty + "RateClass"), RateSubClass = element.GetChildText(empty + "RateSubClass"), MeterCycle = element.GetChildText(empty + "MeterCycle"), MeterCycleDayOfMonth = element.GetChildText(empty + "MeterCycleDayOfMonth"), SpecialNeedsIndicator = element.GetChildText(empty + "SpecialNeedsIndicator"), OldMeterNumber = element.GetChildText(empty + "OldMeterNumber"), MeterOwnerIndicator = element.GetChildText(empty + "MeterOwnerIndicator"), TimeOfUse = element.GetChildText(empty + "TimeOFUse"), EspRateCode = element.GetChildText(empty + "ESPRateCode"), PricingStructureCode = element.GetChildText(empty + "PricingStructureCode"), MeterServiceVoltage = element.GetChildText(empty + "MeterServiceVoltage"), SummaryInterval = element.GetChildText(empty + "SummaryInterval"), }; var changeLoopElement = element.Element(empty + "ServiceMeterChangeLoop"); if (changeLoopElement != null) { var changeElements = changeLoopElement.Elements(empty + "ServiceMeterChange"); foreach (var changeElement in changeElements) { var changeModel = ParseServiceMeterChange(changeElement, namespaces); model.AddChange(changeModel); } } var touLoopElement = element.Element(empty + "ServiceMeterTOULoop"); if (touLoopElement != null) { var touElements = touLoopElement.Elements(empty + "ServiceMeterTOU"); foreach (var touElement in touElements) { var touModel = ParseServiceMeterTou(touElement, namespaces); model.AddTou(touModel); } } var typeLoopElement = element.Element(empty + "ServiceMeterTypeLoop"); if (typeLoopElement != null) { var typeElements = typeLoopElement.Elements(empty + "ServiceMeterType"); foreach (var typeElement in typeElements) { var typeModel = ParseServiceMeterType(typeElement, namespaces); model.AddType(typeModel); } } return(model); }