├── .gitignore ├── ACM ├── ACM.BL │ ├── ACM.BL.csproj │ ├── Address.cs │ ├── AddressRepository.cs │ ├── Customer.cs │ ├── CustomerRepository.cs │ ├── EntityBase.cs │ ├── Order.cs │ ├── OrderItem.cs │ ├── OrderRepository.cs │ ├── Product.cs │ ├── ProductRepository.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── ACM.sln ├── Acme.Common │ ├── Acme.Common.csproj │ ├── ILoggable.cs │ ├── LoggingService.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── StringHandler.cs └── Tests │ ├── ACM.BLTest │ ├── ACM.BLTest.csproj │ ├── CustomerRepositoryTest.cs │ ├── CustomerTest.cs │ ├── OrderRepositoryTest.cs │ ├── ProductRepositoryTest.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config │ └── Acme.CommonTest │ ├── Acme.CommonTest.csproj │ ├── LoggingServiceTest.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── StringHandlerTest.cs │ └── packages.config ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /ACM/ACM.BL/ACM.BL.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {9E83C133-325B-4F2E-A576-DBE94D1268BB} 8 | Library 9 | Properties 10 | ACM.BL 11 | ACM.BL 12 | v4.6.1 13 | 512 14 | true 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | {7509e8f9-6fed-4002-8f48-71b94afb0fe5} 59 | Acme.Common 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /ACM/ACM.BL/Address.cs: -------------------------------------------------------------------------------- 1 | namespace ACM.BL 2 | { 3 | public class Address : EntityBase 4 | { 5 | public Address() 6 | { 7 | 8 | } 9 | public Address(int addressId) 10 | { 11 | AddressId = addressId; 12 | } 13 | 14 | public int AddressId { get; private set; } 15 | public int AddressType { get; set; } 16 | public string City { get; set; } 17 | public string Country { get; set; } 18 | public string PostalCode { get; set; } 19 | public string State { get; set; } 20 | public string StreetLine1 { get; set; } 21 | public string StreetLine2 { get; set; } 22 | 23 | /// 24 | /// Validates the address data. 25 | /// 26 | /// 27 | public override bool Validate() 28 | { 29 | var isValid = true; 30 | 31 | if (PostalCode == null) isValid = false; 32 | 33 | return isValid; 34 | } 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ACM/ACM.BL/AddressRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ACM.BL 4 | { 5 | public class AddressRepository 6 | { 7 | /// 8 | /// Retrieve one address. 9 | /// 10 | public Address Retrieve(int addressId) 11 | { 12 | // Create the instance of the Address class 13 | // Pass in the requested Id 14 | Address address = new Address(addressId); 15 | 16 | // Code that retrieves the defined address 17 | 18 | // Temporary hard coded values to return 19 | // a populated address 20 | if (addressId == 1) 21 | { 22 | address.AddressType = 1; 23 | address.StreetLine1 = "Bag End"; 24 | address.StreetLine2 = "Bagshot row"; 25 | address.City = "Hobbiton"; 26 | address.State = "Shire"; 27 | address.Country = "Middle Earth"; 28 | address.PostalCode = "144"; 29 | 30 | } 31 | return address; 32 | } 33 | 34 | public IEnumerable
RetrieveByCustomerId(int customerId) 35 | { 36 | // Code that retrieves the defined addresses 37 | // for the customer. 38 | 39 | 40 | // Temporary hard-coded values to return 41 | // a set of addresses for a customer 42 | var addressList = new List
(); 43 | Address address = new Address(1) 44 | { 45 | AddressType = 1, 46 | StreetLine1 = "Bag End", 47 | StreetLine2 = "Bagshot row", 48 | City = "Hobbiton", 49 | State = "Shire", 50 | Country = "Middle Earth", 51 | PostalCode = "144" 52 | }; 53 | addressList.Add(address); 54 | 55 | address = new Address(2) 56 | { 57 | AddressType = 2, 58 | StreetLine1 = "Green Dragon", 59 | City = "Bywater", 60 | State = "Shire", 61 | Country = "Middle Earth", 62 | PostalCode = "146" 63 | }; 64 | addressList.Add(address); 65 | 66 | return addressList; 67 | } 68 | 69 | /// 70 | /// Saves the current address. 71 | /// 72 | /// 73 | public bool Save(Address address) 74 | { 75 | var success = true; 76 | 77 | if (address.HasChanges) 78 | { 79 | if (address.IsValid) 80 | { 81 | if (address.IsNew) 82 | { 83 | // Call an Insert Stored Procedure 84 | 85 | } 86 | else 87 | { 88 | // Call an Update Stored Procedure 89 | } 90 | } 91 | else 92 | { 93 | success = false; 94 | } 95 | } 96 | return success; 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /ACM/ACM.BL/Customer.cs: -------------------------------------------------------------------------------- 1 | using Acme.Common; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace ACM.BL 9 | { 10 | public class Customer : EntityBase, ILoggable 11 | { 12 | public Customer() : this(0) 13 | { 14 | 15 | } 16 | public Customer(int customerId) 17 | { 18 | CustomerId = customerId; 19 | AddressList = new List
(); 20 | } 21 | 22 | public List
AddressList { get; set; } 23 | public int CustomerId { get; private set; } 24 | public int CustomerType { get; set; } 25 | public string EmailAddress { get; set; } 26 | 27 | public string FirstName { get; set; } 28 | 29 | public string FullName 30 | { 31 | get 32 | { 33 | string fullName = LastName; 34 | if (!string.IsNullOrWhiteSpace(FirstName)) 35 | { 36 | if (!string.IsNullOrWhiteSpace(fullName)) 37 | { 38 | fullName += ", "; 39 | } 40 | fullName += FirstName; 41 | } 42 | return fullName; 43 | } 44 | } 45 | 46 | public static int InstanceCount { get; set; } 47 | 48 | private string _lastName; 49 | public string LastName 50 | { 51 | get 52 | { 53 | return _lastName; 54 | } 55 | set 56 | { 57 | _lastName = value; 58 | } 59 | } 60 | 61 | // Long form of the Log method 62 | //public string Log() 63 | //{ 64 | // var logString = CustomerId + ": " + 65 | // FullName + " " + 66 | // "Email: " + EmailAddress + " " + 67 | // "Status: " + EntityState.ToString(); 68 | // return logString; 69 | //} 70 | 71 | // Short cut form of the Log method 72 | public string Log() => 73 | $"{CustomerId}: {FullName} Email: {EmailAddress} Status: {EntityState.ToString()}"; 74 | 75 | public override string ToString() => FullName; 76 | 77 | /// 78 | /// Validates the customer data. 79 | /// 80 | /// 81 | public override bool Validate() 82 | { 83 | var isValid = true; 84 | 85 | if (string.IsNullOrWhiteSpace(LastName)) isValid = false; 86 | if (string.IsNullOrWhiteSpace(EmailAddress)) isValid = false; 87 | 88 | return isValid; 89 | } 90 | 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /ACM/ACM.BL/CustomerRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ACM.BL 8 | { 9 | public class CustomerRepository 10 | { 11 | public CustomerRepository() 12 | { 13 | addressRepository = new AddressRepository(); 14 | } 15 | 16 | private AddressRepository addressRepository { get; set; } 17 | 18 | /// 19 | /// Retrieve one customer. 20 | /// 21 | public Customer Retrieve(int customerId) 22 | { 23 | // Create the instance of the Customer class 24 | // Pass in the requested id 25 | Customer customer = new Customer(customerId); 26 | 27 | // Code that retrieves the defined customer 28 | 29 | // Temporary hard-coded values to return 30 | // a populated customer 31 | if (customerId == 1) 32 | { 33 | customer.EmailAddress = "fbaggins@hobbiton.me"; 34 | customer.FirstName = "Frodo"; 35 | customer.LastName = "Baggins"; 36 | customer.AddressList = addressRepository.RetrieveByCustomerId(customerId). 37 | ToList(); 38 | } 39 | return customer; 40 | } 41 | 42 | /// 43 | /// Saves the current customer. 44 | /// 45 | /// 46 | public bool Save(Customer customer) 47 | { 48 | var success = true; 49 | 50 | if (customer.HasChanges) 51 | { 52 | if (customer.IsValid) 53 | { 54 | if (customer.IsNew) 55 | { 56 | // Call an Insert Stored Procedure 57 | 58 | } 59 | else 60 | { 61 | // Call an Update Stored Procedure 62 | } 63 | } 64 | else 65 | { 66 | success = false; 67 | } 68 | } 69 | return success; 70 | } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /ACM/ACM.BL/EntityBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ACM.BL 8 | { 9 | public enum EntityStateOption 10 | { 11 | Active, 12 | Deleted 13 | } 14 | 15 | public abstract class EntityBase 16 | { 17 | public EntityStateOption EntityState { get; set; } 18 | public bool HasChanges { get; set; } 19 | public bool IsNew { get; private set; } 20 | public bool IsValid => Validate(); 21 | 22 | public abstract bool Validate(); 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ACM/ACM.BL/Order.cs: -------------------------------------------------------------------------------- 1 | using Acme.Common; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace ACM.BL 6 | { 7 | public class Order : EntityBase, ILoggable 8 | { 9 | public Order() : this(0) 10 | { 11 | 12 | } 13 | public Order(int orderId) 14 | { 15 | OrderId = orderId; 16 | OrderItems = new List(); 17 | } 18 | 19 | public int CustomerId { get; set; } 20 | public DateTimeOffset? OrderDate { get; set; } 21 | public int OrderId { get; private set; } 22 | public List OrderItems { get; set; } 23 | public int ShippingAddressId { get; set; } 24 | 25 | public string Log() => 26 | $"{OrderId}: Date: {this.OrderDate.Value.Date} Status: {this.EntityState.ToString()}"; 27 | 28 | public override string ToString() => 29 | $"{OrderDate.Value.Date} ({OrderId})"; 30 | 31 | /// 32 | /// Validates the order data. 33 | /// 34 | /// 35 | public override bool Validate() 36 | { 37 | var isValid = true; 38 | 39 | if (OrderDate == null) isValid = false; 40 | 41 | return isValid; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ACM/ACM.BL/OrderItem.cs: -------------------------------------------------------------------------------- 1 | namespace ACM.BL 2 | { 3 | public class OrderItem: EntityBase 4 | { 5 | public OrderItem() 6 | { 7 | 8 | } 9 | public OrderItem(int orderItemId) 10 | { 11 | OrderItemId = orderItemId; 12 | } 13 | 14 | public int OrderItemId { get; private set; } 15 | public int ProductId { get; set; } 16 | public decimal? PurchasePrice { get; set; } 17 | public int Quantity { get; set; } 18 | 19 | /// 20 | /// Retrieve one order item. 21 | /// 22 | public OrderItem Retrieve(int orderItemId) 23 | { 24 | // Code that retrieves the defined order item 25 | 26 | return new OrderItem(); 27 | } 28 | 29 | /// 30 | /// Saves the current order item. 31 | /// 32 | /// 33 | public bool Save() 34 | { 35 | // Code that saves the defined order item 36 | 37 | return true; 38 | } 39 | 40 | /// 41 | /// Validates the order item data. 42 | /// 43 | /// 44 | public override bool Validate() 45 | { 46 | var isValid = true; 47 | 48 | if (Quantity <= 0) isValid = false; 49 | if (ProductId <= 0) isValid = false; 50 | if (PurchasePrice == null) isValid = false; 51 | 52 | return isValid; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /ACM/ACM.BL/OrderRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ACM.BL 4 | { 5 | public class OrderRepository 6 | { 7 | /// 8 | /// Retrieve one order. 9 | /// 10 | public Order Retrieve(int orderId) 11 | { 12 | // Create the instance of the Order class 13 | // Pass in the requested Id 14 | Order order = new Order(orderId); 15 | 16 | // Code that retrieves the defined order 17 | 18 | // Temporary hard-coded values to return 19 | // a populated order 20 | if (orderId == 10) 21 | { 22 | // Use current year in hard-coded data 23 | order.OrderDate = new DateTimeOffset(DateTime.Now.Year, 4, 14, 10, 00, 00, 24 | new TimeSpan(7, 0, 0)); 25 | } 26 | 27 | return order; 28 | } 29 | 30 | /// 31 | /// Saves the current order. 32 | /// 33 | /// 34 | public bool Save(Order order) 35 | { 36 | var success = true; 37 | 38 | if (order.HasChanges) 39 | { 40 | if (order.IsValid) 41 | { 42 | if (order.IsNew) 43 | { 44 | // Call an Insert Stored Procedure 45 | 46 | } 47 | else 48 | { 49 | // Call an Update Stored Procedure 50 | } 51 | } 52 | else 53 | { 54 | success = false; 55 | } 56 | } 57 | return success; 58 | } 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /ACM/ACM.BL/Product.cs: -------------------------------------------------------------------------------- 1 | using Acme.Common; 2 | 3 | namespace ACM.BL 4 | { 5 | public class Product : EntityBase, ILoggable 6 | { 7 | public Product() 8 | { 9 | 10 | } 11 | public Product(int productId) 12 | { 13 | ProductId = productId; 14 | } 15 | 16 | public decimal? CurrentPrice { get; set; } 17 | public string ProductDescription { get; set; } 18 | public int ProductId { get; private set; } 19 | 20 | private string _productName; 21 | public string ProductName 22 | { 23 | get 24 | { 25 | return _productName.InsertSpaces(); 26 | } 27 | set 28 | { 29 | _productName = value; 30 | } 31 | } 32 | 33 | public string Log() => 34 | $"{ProductId}: {ProductName} Detail: {ProductDescription} Status: {EntityState.ToString()}"; 35 | 36 | public override string ToString() => ProductName; 37 | 38 | /// 39 | /// Validates the product data. 40 | /// 41 | /// 42 | public override bool Validate() 43 | { 44 | var isValid = true; 45 | 46 | if (string.IsNullOrWhiteSpace(ProductName)) isValid = false; 47 | if (CurrentPrice == null) isValid = false; 48 | 49 | return isValid; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ACM/ACM.BL/ProductRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ACM.BL 4 | { 5 | public class ProductRepository 6 | { 7 | /// 8 | /// Retrieve one product. 9 | /// 10 | public Product Retrieve(int productId) 11 | { 12 | // Create the instance of the Product class 13 | // Pass in the requested Id 14 | Product product = new Product(productId); 15 | 16 | // Code that retrieves the defined product 17 | 18 | // Temporary hard-coded values to return 19 | // a populated product 20 | if (productId == 2) 21 | { 22 | product.ProductName = "Sunflowers"; 23 | product.ProductDescription = "Assorted Size Set of 4 Bright Yellow Mini Sunflowers"; 24 | product.CurrentPrice = 15.96M; 25 | } 26 | Object myObject = new Object(); 27 | Console.WriteLine($"Object: {myObject.ToString()}"); 28 | Console.WriteLine($"Product: {product.ToString()}"); 29 | return product; 30 | } 31 | 32 | /// 33 | /// Saves the current product. 34 | /// 35 | /// 36 | public bool Save(Product product) 37 | { 38 | var success = true; 39 | 40 | if (product.HasChanges) 41 | { 42 | if (product.IsValid) 43 | { 44 | if (product.IsNew) 45 | { 46 | // Call an Insert Stored Procedure 47 | 48 | } 49 | else 50 | { 51 | // Call an Update Stored Procedure 52 | } 53 | } 54 | else 55 | { 56 | success = false; 57 | } 58 | } 59 | return success; 60 | } 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ACM/ACM.BL/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ACM.BL")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ACM.BL")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("9e83c133-325b-4f2e-a576-dbe94d1268bb")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ACM/ACM.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.271 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ACM.BL", "ACM.BL\ACM.BL.csproj", "{9E83C133-325B-4F2E-A576-DBE94D1268BB}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{3BE90661-61D4-43FC-A4DA-22B319CE1A48}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ACM.BLTest", "Tests\ACM.BLTest\ACM.BLTest.csproj", "{8672FA7F-D955-4A53-BC5D-CB15FD6B4F3E}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Acme.Common", "Acme.Common\Acme.Common.csproj", "{7509E8F9-6FED-4002-8F48-71B94AFB0FE5}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Acme.CommonTest", "Tests\Acme.CommonTest\Acme.CommonTest.csproj", "{660F4E67-57C6-4D4D-A255-C3D96BD50301}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Any CPU = Debug|Any CPU 19 | Release|Any CPU = Release|Any CPU 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {9E83C133-325B-4F2E-A576-DBE94D1268BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {9E83C133-325B-4F2E-A576-DBE94D1268BB}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {9E83C133-325B-4F2E-A576-DBE94D1268BB}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {9E83C133-325B-4F2E-A576-DBE94D1268BB}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {8672FA7F-D955-4A53-BC5D-CB15FD6B4F3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {8672FA7F-D955-4A53-BC5D-CB15FD6B4F3E}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {8672FA7F-D955-4A53-BC5D-CB15FD6B4F3E}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {8672FA7F-D955-4A53-BC5D-CB15FD6B4F3E}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {7509E8F9-6FED-4002-8F48-71B94AFB0FE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {7509E8F9-6FED-4002-8F48-71B94AFB0FE5}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {7509E8F9-6FED-4002-8F48-71B94AFB0FE5}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {7509E8F9-6FED-4002-8F48-71B94AFB0FE5}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {660F4E67-57C6-4D4D-A255-C3D96BD50301}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {660F4E67-57C6-4D4D-A255-C3D96BD50301}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {660F4E67-57C6-4D4D-A255-C3D96BD50301}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {660F4E67-57C6-4D4D-A255-C3D96BD50301}.Release|Any CPU.Build.0 = Release|Any CPU 38 | EndGlobalSection 39 | GlobalSection(SolutionProperties) = preSolution 40 | HideSolutionNode = FALSE 41 | EndGlobalSection 42 | GlobalSection(NestedProjects) = preSolution 43 | {8672FA7F-D955-4A53-BC5D-CB15FD6B4F3E} = {3BE90661-61D4-43FC-A4DA-22B319CE1A48} 44 | {660F4E67-57C6-4D4D-A255-C3D96BD50301} = {3BE90661-61D4-43FC-A4DA-22B319CE1A48} 45 | EndGlobalSection 46 | GlobalSection(ExtensibilityGlobals) = postSolution 47 | SolutionGuid = {1E0420EE-7F65-4A0B-B96E-94B46F568BC2} 48 | EndGlobalSection 49 | EndGlobal 50 | -------------------------------------------------------------------------------- /ACM/Acme.Common/Acme.Common.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {7509E8F9-6FED-4002-8F48-71B94AFB0FE5} 8 | Library 9 | Properties 10 | Acme.Common 11 | Acme.Common 12 | v4.6.1 13 | 512 14 | true 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /ACM/Acme.Common/ILoggable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Acme.Common 8 | { 9 | public interface ILoggable 10 | { 11 | string Log(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ACM/Acme.Common/LoggingService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Acme.Common 8 | { 9 | public static class LoggingService 10 | { 11 | public static void WriteToFile(List itemsToLog) 12 | { 13 | foreach (var item in itemsToLog) 14 | { 15 | Console.WriteLine(item.Log()); 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ACM/Acme.Common/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Acme.Common")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Acme.Common")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("7509e8f9-6fed-4002-8f48-71b94afb0fe5")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ACM/Acme.Common/StringHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Acme.Common 8 | { 9 | public static class StringHandler 10 | { 11 | /// 12 | /// Inserts spaces before each capital letter in a string 13 | /// 14 | /// 15 | /// 16 | public static string InsertSpaces(this string source) 17 | { 18 | string result = string.Empty; 19 | 20 | if (!String.IsNullOrWhiteSpace(source)) 21 | { 22 | foreach (char letter in source) 23 | { 24 | if (char.IsUpper(letter)) 25 | { 26 | // Trim any spaces already there 27 | result = result.Trim(); 28 | result += " "; 29 | } 30 | result += letter; 31 | } 32 | } 33 | result = result.Trim(); 34 | return result; 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ACM/Tests/ACM.BLTest/ACM.BLTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {8672FA7F-D955-4A53-BC5D-CB15FD6B4F3E} 9 | Library 10 | Properties 11 | ACM.BLTest 12 | ACM.BLTest 13 | v4.6.1 14 | 512 15 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 16 | 15.0 17 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 18 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 19 | False 20 | UnitTest 21 | 22 | 23 | 24 | 25 | true 26 | full 27 | false 28 | bin\Debug\ 29 | DEBUG;TRACE 30 | prompt 31 | 4 32 | 33 | 34 | pdbonly 35 | true 36 | bin\Release\ 37 | TRACE 38 | prompt 39 | 4 40 | 41 | 42 | 43 | ..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll 44 | 45 | 46 | ..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | {9e83c133-325b-4f2e-a576-dbe94d1268bb} 64 | ACM.BL 65 | 66 | 67 | 68 | 69 | 70 | 71 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /ACM/Tests/ACM.BLTest/CustomerRepositoryTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using ACM.BL; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | 6 | namespace ACM.BLTest 7 | { 8 | [TestClass] 9 | public class CustomerRepositoryTest 10 | { 11 | [TestMethod] 12 | public void RetrieveValid() 13 | { 14 | //-- Arrange 15 | var customerRepository = new CustomerRepository(); 16 | var expected = new Customer(1) 17 | { 18 | EmailAddress = "fbaggins@hobbiton.me", 19 | FirstName = "Frodo", 20 | LastName = "Baggins" 21 | }; 22 | 23 | //-- Act 24 | var actual = customerRepository.Retrieve(1); 25 | 26 | //-- Assert 27 | Assert.AreEqual(expected.CustomerId, actual.CustomerId); 28 | Assert.AreEqual(expected.EmailAddress, actual.EmailAddress); 29 | Assert.AreEqual(expected.FirstName, actual.FirstName); 30 | Assert.AreEqual(expected.LastName, actual.LastName); 31 | } 32 | 33 | [TestMethod] 34 | public void RetrieveExistingWithAddress() 35 | { 36 | //-- Arrange 37 | var customerRepository = new CustomerRepository(); 38 | var expected = new Customer(1) 39 | { 40 | EmailAddress = "fbaggins@hobbiton.me", 41 | FirstName = "Frodo", 42 | LastName = "Baggins", 43 | AddressList = new List
() 44 | { 45 | new Address() 46 | { 47 | AddressType = 1, 48 | StreetLine1 = "Bag End", 49 | StreetLine2 = "Bagshot row", 50 | City = "Hobbiton", 51 | State = "Shire", 52 | Country = "Middle Earth", 53 | PostalCode = "144" 54 | }, 55 | new Address() 56 | { 57 | AddressType = 2, 58 | StreetLine1 = "Green Dragon", 59 | City = "Bywater", 60 | State = "Shire", 61 | Country = "Middle Earth", 62 | PostalCode = "146" 63 | } 64 | } 65 | }; 66 | 67 | //-- Act 68 | var actual = customerRepository.Retrieve(1); 69 | 70 | //-- Assert 71 | Assert.AreEqual(expected.CustomerId, actual.CustomerId); 72 | Assert.AreEqual(expected.EmailAddress, actual.EmailAddress); 73 | Assert.AreEqual(expected.FirstName, actual.FirstName); 74 | Assert.AreEqual(expected.LastName, actual.LastName); 75 | 76 | for (int i = 0; i < 1; i++) 77 | { 78 | Assert.AreEqual(expected.AddressList[i].AddressType, actual.AddressList[i].AddressType); 79 | Assert.AreEqual(expected.AddressList[i].StreetLine1, actual.AddressList[i].StreetLine1); 80 | Assert.AreEqual(expected.AddressList[i].City, actual.AddressList[i].City); 81 | Assert.AreEqual(expected.AddressList[i].State, actual.AddressList[i].State); 82 | Assert.AreEqual(expected.AddressList[i].Country, actual.AddressList[i].Country); 83 | Assert.AreEqual(expected.AddressList[i].PostalCode, actual.AddressList[i].PostalCode); 84 | } 85 | } 86 | 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /ACM/Tests/ACM.BLTest/CustomerTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using ACM.BL; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | 5 | namespace ACM.BLTest 6 | { 7 | [TestClass] 8 | public class CustomerTest 9 | { 10 | [TestMethod] 11 | public void FullNameTestValid() 12 | { 13 | //-- Arrange 14 | Customer customer = new Customer 15 | { 16 | FirstName = "Bilbo", 17 | LastName = "Baggins" 18 | }; 19 | string expected = "Baggins, Bilbo"; 20 | 21 | //-- Act 22 | string actual = customer.FullName; 23 | 24 | //-- Assert 25 | Assert.AreEqual(expected, actual); 26 | } 27 | 28 | [TestMethod] 29 | public void FullNameFirstNameEmpty() 30 | { 31 | //-- Arrange 32 | Customer customer = new Customer 33 | { 34 | LastName = "Baggins" 35 | }; 36 | string expected = "Baggins"; 37 | 38 | //-- Act 39 | string actual = customer.FullName; 40 | 41 | //-- Assert 42 | Assert.AreEqual(expected, actual); 43 | } 44 | 45 | [TestMethod] 46 | public void FullNameLastNameEmpty() 47 | { 48 | //-- Arrange 49 | Customer customer = new Customer 50 | { 51 | FirstName = "Bilbo" 52 | }; 53 | string expected = "Bilbo"; 54 | 55 | //-- Act 56 | string actual = customer.FullName; 57 | 58 | //-- Assert 59 | Assert.AreEqual(expected, actual); 60 | } 61 | 62 | [TestMethod] 63 | public void StaticTest() 64 | { 65 | //-- Arrange 66 | var c1 = new Customer(); 67 | c1.FirstName = "Bilbo"; 68 | Customer.InstanceCount += 1; 69 | 70 | var c2 = new Customer(); 71 | c2.FirstName = "Frodo"; 72 | Customer.InstanceCount += 1; 73 | 74 | var c3 = new Customer(); 75 | c3.FirstName = "Rosie"; 76 | Customer.InstanceCount += 1; 77 | 78 | //-- Act 79 | 80 | //-- Assert 81 | Assert.AreEqual(3, Customer.InstanceCount); 82 | } 83 | 84 | [TestMethod] 85 | public void ValidateValid() 86 | { 87 | //-- Arrange 88 | var customer = new Customer 89 | { 90 | LastName = "Baggins", 91 | EmailAddress = "fbaggins@hobbiton.me" 92 | }; 93 | 94 | var expected = true; 95 | 96 | //-- Act 97 | var actual = customer.Validate(); 98 | 99 | //-- Assert 100 | Assert.AreEqual(expected, actual); 101 | } 102 | 103 | [TestMethod] 104 | public void ValidateMissingLastName() 105 | { 106 | //-- Arrange 107 | var customer = new Customer 108 | { 109 | EmailAddress = "fbaggins@hobbiton.me" 110 | }; 111 | 112 | var expected = false; 113 | 114 | //-- Act 115 | var actual = customer.Validate(); 116 | 117 | //-- Assert 118 | Assert.AreEqual(expected, actual); 119 | } 120 | 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /ACM/Tests/ACM.BLTest/OrderRepositoryTest.cs: -------------------------------------------------------------------------------- 1 | using ACM.BL; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using System; 4 | 5 | namespace ACM.BLTest 6 | { 7 | [TestClass()] 8 | public class OrderRepositoryTests 9 | { 10 | [TestMethod()] 11 | public void RetrieveOrderDisplayTest() 12 | { 13 | //-- Arrange 14 | var orderRepository = new OrderRepository(); 15 | var expected = new Order(10) 16 | { 17 | OrderDate = new DateTimeOffset(DateTime.Now.Year, 4, 14, 10, 00, 00, 18 | new TimeSpan(7, 0, 0)), 19 | }; 20 | 21 | //-- Act 22 | var actual = orderRepository.Retrieve(10); 23 | 24 | //-- Assert 25 | Assert.AreEqual(expected.OrderDate, actual.OrderDate); 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /ACM/Tests/ACM.BLTest/ProductRepositoryTest.cs: -------------------------------------------------------------------------------- 1 | using ACM.BL; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace ACM.BLTest 5 | { 6 | [TestClass()] 7 | public class ProductRepositoryTest 8 | { 9 | [TestMethod()] 10 | public void RetrieveTest() 11 | { 12 | //-- Arrange 13 | var productRepository = new ProductRepository(); 14 | var expected = new Product(2) 15 | { 16 | CurrentPrice = 15.96M, 17 | ProductDescription = "Assorted Size Set of 4 Bright Yellow Mini Sunflowers", 18 | ProductName = "Sunflowers" 19 | }; 20 | 21 | //-- Act 22 | var actual = productRepository.Retrieve(2); 23 | 24 | //-- Assert 25 | Assert.AreEqual(expected.CurrentPrice, actual.CurrentPrice); 26 | Assert.AreEqual(expected.ProductDescription, actual.ProductDescription); 27 | Assert.AreEqual(expected.ProductName, actual.ProductName); 28 | } 29 | 30 | [TestMethod()] 31 | public void SaveTestValid() 32 | { 33 | //-- Arrange 34 | var productRepository = new ProductRepository(); 35 | var updatedProduct = new Product(2) 36 | { 37 | CurrentPrice = 18M, 38 | ProductDescription = "Assorted Size Set of 4 Bright Yellow Mini Sunflowers", 39 | ProductName = "Sunflowers", 40 | HasChanges = true 41 | }; 42 | 43 | //-- Act 44 | var actual = productRepository.Save(updatedProduct); 45 | 46 | //-- Assert 47 | Assert.AreEqual(true, actual); 48 | } 49 | 50 | [TestMethod()] 51 | public void SaveTestMissingPrice() 52 | { 53 | //-- Arrange 54 | var productRepository = new ProductRepository(); 55 | var updatedProduct = new Product(2) 56 | { 57 | CurrentPrice = null, 58 | ProductDescription = "Assorted Size Set of 4 Bright Yellow Mini Sunflowers", 59 | ProductName = "Sunflowers", 60 | HasChanges = true 61 | }; 62 | 63 | //-- Act 64 | var actual = productRepository.Save(updatedProduct); 65 | 66 | //-- Assert 67 | Assert.AreEqual(false, actual); 68 | } 69 | 70 | 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /ACM/Tests/ACM.BLTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("ACM.BLTest")] 6 | [assembly: AssemblyDescription("")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: AssemblyCompany("")] 9 | [assembly: AssemblyProduct("ACM.BLTest")] 10 | [assembly: AssemblyCopyright("Copyright © 2019")] 11 | [assembly: AssemblyTrademark("")] 12 | [assembly: AssemblyCulture("")] 13 | 14 | [assembly: ComVisible(false)] 15 | 16 | [assembly: Guid("8672fa7f-d955-4a53-bc5d-cb15fd6b4f3e")] 17 | 18 | // [assembly: AssemblyVersion("1.0.*")] 19 | [assembly: AssemblyVersion("1.0.0.0")] 20 | [assembly: AssemblyFileVersion("1.0.0.0")] 21 | -------------------------------------------------------------------------------- /ACM/Tests/ACM.BLTest/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ACM/Tests/Acme.CommonTest/Acme.CommonTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {660F4E67-57C6-4D4D-A255-C3D96BD50301} 9 | Library 10 | Properties 11 | Acme.CommonTest 12 | Acme.CommonTest 13 | v4.6.1 14 | 512 15 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 16 | 15.0 17 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 18 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 19 | False 20 | UnitTest 21 | 22 | 23 | 24 | 25 | true 26 | full 27 | false 28 | bin\Debug\ 29 | DEBUG;TRACE 30 | prompt 31 | 4 32 | 33 | 34 | pdbonly 35 | true 36 | bin\Release\ 37 | TRACE 38 | prompt 39 | 4 40 | 41 | 42 | 43 | ..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll 44 | 45 | 46 | ..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | {9E83C133-325B-4F2E-A576-DBE94D1268BB} 62 | ACM.BL 63 | 64 | 65 | {7509e8f9-6fed-4002-8f48-71b94afb0fe5} 66 | Acme.Common 67 | 68 | 69 | 70 | 71 | 72 | 73 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /ACM/Tests/Acme.CommonTest/LoggingServiceTest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ACM.BL; 3 | using Acme.Common; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | 6 | namespace Acme.CommonTest 7 | { 8 | [TestClass] 9 | public class LoggingServiceTest 10 | { 11 | [TestMethod] 12 | public void WriteToFileTest() 13 | { 14 | // Arrange 15 | var changedItems = new List(); 16 | 17 | var customer = new Customer(1) 18 | { 19 | EmailAddress = "fbaggins@hobbiton.me", 20 | FirstName = "Frodo", 21 | LastName = "Baggins", 22 | AddressList = null 23 | }; 24 | changedItems.Add(customer); 25 | 26 | var product = new Product(2) 27 | { 28 | ProductName = "Rake", 29 | ProductDescription = "Garden Rake with Steel Head", 30 | CurrentPrice = 6M 31 | }; 32 | changedItems.Add(product); 33 | 34 | // Act 35 | LoggingService.WriteToFile(changedItems); 36 | 37 | // Assert 38 | // Nothing here to assert 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ACM/Tests/Acme.CommonTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Acme.CommonTest")] 6 | [assembly: AssemblyDescription("")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: AssemblyCompany("")] 9 | [assembly: AssemblyProduct("Acme.CommonTest")] 10 | [assembly: AssemblyCopyright("Copyright © 2019")] 11 | [assembly: AssemblyTrademark("")] 12 | [assembly: AssemblyCulture("")] 13 | 14 | [assembly: ComVisible(false)] 15 | 16 | [assembly: Guid("660f4e67-57c6-4d4d-a255-c3d96bd50301")] 17 | 18 | // [assembly: AssemblyVersion("1.0.*")] 19 | [assembly: AssemblyVersion("1.0.0.0")] 20 | [assembly: AssemblyFileVersion("1.0.0.0")] 21 | -------------------------------------------------------------------------------- /ACM/Tests/Acme.CommonTest/StringHandlerTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Acme.Common; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | 5 | namespace Acme.CommonTest 6 | { 7 | [TestClass] 8 | public class StringHandlerTest 9 | { 10 | [TestMethod] 11 | public void InsertSpacesTestValid() 12 | { 13 | // Arrange 14 | var source = "SonicScrewdriver"; 15 | var expected = "Sonic Screwdriver"; 16 | 17 | // Act 18 | var actual = source.InsertSpaces(); 19 | 20 | // Assert 21 | Assert.AreEqual(expected, actual); 22 | } 23 | 24 | [TestMethod] 25 | public void InsertSpacesTestWithExistingSpace() 26 | { 27 | // Arrange 28 | var source = "Sonic Screwdriver"; 29 | var expected = "Sonic Screwdriver"; 30 | 31 | // Act 32 | var actual = source.InsertSpaces(); 33 | 34 | // Assert 35 | Assert.AreEqual(expected, actual); 36 | } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ACM/Tests/Acme.CommonTest/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Deborah Kurata 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CSharp-OOP 2 | Materials for my ["Object-Oriented Programming Fundamentals in C#"](https://app.pluralsight.com/library/courses/object-oriented-programming-fundamentals-csharp) course on Pluralsight. 3 | --------------------------------------------------------------------------------