From f2d8532e46b57e2dfa79fd89fe4772f5ca3565ed Mon Sep 17 00:00:00 2001 From: "Michael A. Vickers" Date: Tue, 16 Aug 2022 15:11:10 -0400 Subject: [PATCH] Change package shape from new() to class. --- Cargo.Tests/Unit/Common/ContentModels.cs | 10 ++++++++ Cargo.Tests/Unit/Package.cs | 29 +++++++++++++++--------- Cargo/Bus.cs | 8 +++---- Cargo/Package.cs | 2 +- Cargo/Station.cs | 2 +- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Cargo.Tests/Unit/Common/ContentModels.cs b/Cargo.Tests/Unit/Common/ContentModels.cs index ee22a3e..c819197 100644 --- a/Cargo.Tests/Unit/Common/ContentModels.cs +++ b/Cargo.Tests/Unit/Common/ContentModels.cs @@ -27,4 +27,14 @@ public ContentModel1() Int1 = 0; } } + + public class ContentModel2 + { + public string String1 { get; set; } + + public ContentModel2(string string1) + { + String1 = string1; + } + } } diff --git a/Cargo.Tests/Unit/Package.cs b/Cargo.Tests/Unit/Package.cs index ed912c2..3e30edb 100644 --- a/Cargo.Tests/Unit/Package.cs +++ b/Cargo.Tests/Unit/Package.cs @@ -9,21 +9,28 @@ public class Package [Fact] public void Instantiation() { - Package package; + Package package1; + Package package2; - var contents = new ContentModel1(); + var contents1 = new ContentModel1(); - Assert.Throws(() => package = Cargo.Package.New()); + Assert.Throws(() => package1 = Cargo.Package.New()); - package = Cargo.Package.New(contents); + package1 = Cargo.Package.New(contents1); - Assert.False(package.IsAborted); - Assert.False(package.IsErrored); - Assert.Null(package.LastStationResult); - Assert.NotNull(package.Results); - Assert.Empty(package.Results); - Assert.Equal(package.Contents, contents); - Assert.Null(package.AbortedWith); + Assert.False(package1.IsAborted); + Assert.False(package1.IsErrored); + Assert.Null(package1.LastStationResult); + Assert.NotNull(package1.Results); + Assert.Empty(package1.Results); + Assert.Equal(package1.Contents, contents1); + Assert.Null(package1.AbortedWith); + + var contents2 = new ContentModel2("testing123"); + + package2 = Cargo.Package.New(contents2); + + Assert.Equal("testing123", package2.Contents.String1); } } } diff --git a/Cargo/Bus.cs b/Cargo/Bus.cs index ed6ca8f..c1294b7 100644 --- a/Cargo/Bus.cs +++ b/Cargo/Bus.cs @@ -8,12 +8,12 @@ namespace LightPath.Cargo { public static class Bus { - public static Bus New() where TContent : new() + public static Bus New() where TContent : class { return Bus.New(); } - internal static Bus SetAndReturn(this Bus bus, string propertyName, object value) where TContent : new() + internal static Bus SetAndReturn(this Bus bus, string propertyName, object value) where TContent : class { var property = typeof(Bus).GetProperty(propertyName, BindingFlags.NonPublic | BindingFlags.Instance); @@ -25,7 +25,7 @@ public static class Bus } } - public class Bus where TContent : new() + public class Bus where TContent : class { private Type _finalStation { get; set; } private Package _package { get; set; } @@ -122,7 +122,7 @@ public Bus WithService(TService service) return this; } - public Bus WithStation() where TStation : new() + public Bus WithStation() where TStation : class { _stations.Add(typeof(TStation)); diff --git a/Cargo/Package.cs b/Cargo/Package.cs index 0c25c2d..1053d5d 100644 --- a/Cargo/Package.cs +++ b/Cargo/Package.cs @@ -6,7 +6,7 @@ namespace LightPath.Cargo { public static class Package { - public static Package New(params object[] parameters) where TContents : new() + public static Package New(params object[] parameters) where TContents : class { return Package.New(parameters); } diff --git a/Cargo/Station.cs b/Cargo/Station.cs index 1a9464d..4d94d0f 100644 --- a/Cargo/Station.cs +++ b/Cargo/Station.cs @@ -24,7 +24,7 @@ public enum Output public static class Result { - public static Result New(Station station, Output output, Exception exception = null) where T : new() + public static Result New(Station station, Output output, Exception exception = null) where T : class { return new Result(station, output, exception); }