├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── UnitTestingTools.sln ├── src └── UTT.Domain │ ├── Core │ ├── Entity.cs │ └── IRepository.cs │ ├── Customers │ ├── Customer.cs │ ├── Events │ │ └── CustomerEmailNotification.cs │ ├── Repository │ │ └── ICustomerRepository.cs │ ├── Services │ │ ├── CustomerService.cs │ │ └── ICustomerService.cs │ └── Validations │ │ └── CustomerSelfValidation.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── UTT.Domain.csproj │ └── packages.config └── tests └── UTT.Domain.Tests ├── Customers ├── CustomerServiceTests.cs ├── CustomerTests.cs └── CustomerTestsFixture.cs ├── Properties └── AssemblyInfo.cs ├── UTT.Domain.Tests.csproj ├── app.config └── packages.config /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Eduardo Pires 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 | 2 | Unit Testing Tools 3 | ===================== 4 | Great tools to increase the quality of your unit tests. 5 | 6 | ## Frameworks / Tools: 7 | 8 | - XUnit 9 | - Runners 10 | - Collection Fixture 11 | - Good use of decorators for better recognizing 12 | - MOQ 13 | - Use of Verify Assertion 14 | - AutoMoq 15 | - Used with XUnit Fixture 16 | - Bogus 17 | - Generation of random data 18 | - Fluent Assertions 19 | - Increasing the assertion expression 20 | 21 | ## About: 22 | This project was developed by [Eduardo Pires](http://eduardopires.net.br) under the [MIT license](LICENSE). 23 | -------------------------------------------------------------------------------- /UnitTestingTools.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26430.13 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UTT.Domain", "src\UTT.Domain\UTT.Domain.csproj", "{AEC738F7-D84B-4F07-AB17-2A091DC7BC89}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UTT.Domain.Tests", "tests\UTT.Domain.Tests\UTT.Domain.Tests.csproj", "{830DBD32-DBC9-4181-B672-6F3384D056F8}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {AEC738F7-D84B-4F07-AB17-2A091DC7BC89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {AEC738F7-D84B-4F07-AB17-2A091DC7BC89}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {AEC738F7-D84B-4F07-AB17-2A091DC7BC89}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {AEC738F7-D84B-4F07-AB17-2A091DC7BC89}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {830DBD32-DBC9-4181-B672-6F3384D056F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {830DBD32-DBC9-4181-B672-6F3384D056F8}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {830DBD32-DBC9-4181-B672-6F3384D056F8}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {830DBD32-DBC9-4181-B672-6F3384D056F8}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /src/UTT.Domain/Core/Entity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation.Results; 3 | using MediatR; 4 | 5 | namespace UTT.Domain.Core 6 | { 7 | public abstract class Entity 8 | { 9 | public Guid Id { get; protected set; } 10 | public ValidationResult ValidationResult { get; protected set; } 11 | 12 | public abstract bool IsValid(); 13 | 14 | public override bool Equals(object obj) 15 | { 16 | var compareTo = obj as Entity; 17 | 18 | if (ReferenceEquals(this, compareTo)) return true; 19 | if (ReferenceEquals(null, compareTo)) return false; 20 | 21 | return Id.Equals(compareTo.Id); 22 | } 23 | 24 | public static bool operator ==(Entity a, Entity b) 25 | { 26 | if (ReferenceEquals(a, null) && ReferenceEquals(b, null)) 27 | return true; 28 | 29 | if (ReferenceEquals(a, null) || ReferenceEquals(b, null)) 30 | return false; 31 | 32 | return a.Equals(b); 33 | } 34 | 35 | public static bool operator !=(Entity a, Entity b) 36 | { 37 | return !(a == b); 38 | } 39 | 40 | public override int GetHashCode() 41 | { 42 | return (GetType().GetHashCode() * 907) + Id.GetHashCode(); 43 | } 44 | 45 | public override string ToString() 46 | { 47 | return GetType().Name + " [Id=" + Id + "]"; 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/UTT.Domain/Core/IRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | 5 | namespace UTT.Domain.Core 6 | { 7 | public interface IRepository : IDisposable where TEntity : Entity 8 | { 9 | void Add(TEntity obj); 10 | TEntity GetById(Guid id); 11 | IEnumerable GetAll(); 12 | void Update(TEntity obj); 13 | void Remove(Guid id); 14 | IEnumerable Find(Expression> predicate); 15 | int SaveChanges(); 16 | } 17 | } -------------------------------------------------------------------------------- /src/UTT.Domain/Customers/Customer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UTT.Domain.Core; 3 | using UTT.Domain.Customers.Validations; 4 | 5 | namespace UTT.Domain.Customers 6 | { 7 | public class Customer : Entity 8 | { 9 | public string Name { get; private set; } 10 | public string LastName { get; private set; } 11 | public DateTime BirthDate { get; private set; } 12 | public DateTime RegisterDate { get; private set; } 13 | public string Email { get; private set; } 14 | public bool Active { get; private set; } 15 | 16 | protected Customer() { } 17 | 18 | public Customer(Guid id, string name, string lastName, DateTime birthDate, string email, bool active, DateTime registerDate) 19 | { 20 | Id = id; 21 | Name = name; 22 | LastName = lastName; 23 | BirthDate = birthDate; 24 | Email = email; 25 | Active = active; 26 | RegisterDate = registerDate; 27 | } 28 | 29 | public string FullName() 30 | { 31 | return Name + " " + LastName; 32 | } 33 | 34 | public bool IsSpecial() 35 | { 36 | return RegisterDate < DateTime.Now.AddYears(-3) && Active; 37 | } 38 | 39 | public void SetInactive() 40 | { 41 | Active = false; 42 | } 43 | 44 | public override bool IsValid() 45 | { 46 | ValidationResult = new CustomerSelfValidation().Validate(this); 47 | return ValidationResult.IsValid; 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/UTT.Domain/Customers/Events/CustomerEmailNotification.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | using UTT.Domain.Core; 3 | 4 | namespace UTT.Domain.Customers.Events 5 | { 6 | public class CustomerEmailNotification : INotification 7 | { 8 | public string From { get; private set; } 9 | public string To { get; private set; } 10 | public string Subject { get; private set; } 11 | public string Message { get; private set; } 12 | 13 | public CustomerEmailNotification(string @from, string to, string subject, string message) 14 | { 15 | From = @from; 16 | To = to; 17 | Subject = subject; 18 | Message = message; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/UTT.Domain/Customers/Repository/ICustomerRepository.cs: -------------------------------------------------------------------------------- 1 | using UTT.Domain.Core; 2 | 3 | namespace UTT.Domain.Customers.Repository 4 | { 5 | public interface ICustomerRepository : IRepository 6 | { 7 | Customer GetByEmail(string email); 8 | } 9 | } -------------------------------------------------------------------------------- /src/UTT.Domain/Customers/Services/CustomerService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using MediatR; 4 | using UTT.Domain.Customers.Events; 5 | using UTT.Domain.Customers.Repository; 6 | 7 | namespace UTT.Domain.Customers.Services 8 | { 9 | public class CustomerService : ICustomerService 10 | { 11 | private readonly ICustomerRepository _customerRepository; 12 | private readonly IMediator _mediator; 13 | 14 | public CustomerService(ICustomerRepository customerRepository, 15 | IMediator mediator) 16 | { 17 | _customerRepository = customerRepository; 18 | _mediator = mediator; 19 | } 20 | 21 | public IEnumerable GetAllActive() 22 | { 23 | return _customerRepository.GetAll().Where(c => c.Active); 24 | } 25 | 26 | public void Register(Customer customer) 27 | { 28 | if(!customer.IsValid()) 29 | return; 30 | 31 | _customerRepository.Add(customer); 32 | _mediator.Publish(new CustomerEmailNotification("admin@me.com", customer.Email, "Welcome", "Hello!")); 33 | } 34 | 35 | public void Update(Customer customer) 36 | { 37 | if (!customer.IsValid()) 38 | return; 39 | 40 | _customerRepository.Update(customer); 41 | _mediator.Publish(new CustomerEmailNotification("admin@me.com", customer.Email, "You changed", "Take a look!")); 42 | } 43 | 44 | public void Inactivate(Customer customer) 45 | { 46 | if (!customer.IsValid()) 47 | return; 48 | 49 | customer.SetInactive(); 50 | _customerRepository.Update(customer); 51 | _mediator.Publish(new CustomerEmailNotification("admin@me.com", customer.Email, "See you soon", "Take a look!")); 52 | } 53 | 54 | public void Remove(Customer customer) 55 | { 56 | _customerRepository.Remove(customer.Id); 57 | _mediator.Publish(new CustomerEmailNotification("admin@me.com", customer.Email, "Good bye", "Hasta la vista!")); 58 | } 59 | 60 | public void Dispose() 61 | { 62 | _customerRepository.Dispose(); 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /src/UTT.Domain/Customers/Services/ICustomerService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace UTT.Domain.Customers.Services 5 | { 6 | public interface ICustomerService : IDisposable 7 | { 8 | IEnumerable GetAllActive(); 9 | void Register(Customer customer); 10 | void Update(Customer customer); 11 | void Remove(Customer customer); 12 | void Inactivate(Customer customer); 13 | } 14 | } -------------------------------------------------------------------------------- /src/UTT.Domain/Customers/Validations/CustomerSelfValidation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentValidation; 3 | 4 | namespace UTT.Domain.Customers.Validations 5 | { 6 | public class CustomerSelfValidation : AbstractValidator 7 | { 8 | public CustomerSelfValidation() 9 | { 10 | RuleFor(c => c.Name) 11 | .NotEmpty().WithMessage("Please ensure you have entered the Name") 12 | .Length(2, 150).WithMessage("The Name must have between 2 and 150 characters"); 13 | 14 | RuleFor(c => c.LastName) 15 | .NotEmpty().WithMessage("Please ensure you have entered the Last Name") 16 | .Length(2, 150).WithMessage("The Last Name must have between 2 and 150 characters"); 17 | 18 | RuleFor(c => c.BirthDate) 19 | .NotEmpty() 20 | .Must(HaveMinimumAge) 21 | .WithMessage("The customer must have 18 years or more"); 22 | 23 | RuleFor(c => c.Email) 24 | .NotEmpty() 25 | .EmailAddress(); 26 | 27 | RuleFor(c => c.Id) 28 | .NotEqual(Guid.Empty); 29 | } 30 | 31 | public static bool HaveMinimumAge(DateTime birthDate) 32 | { 33 | return birthDate <= DateTime.Now.AddYears(-18); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /src/UTT.Domain/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("UTT.Domain")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("UTT.Domain")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 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("aec738f7-d84b-4f07-ab17-2a091dc7bc89")] 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 | -------------------------------------------------------------------------------- /src/UTT.Domain/UTT.Domain.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {AEC738F7-D84B-4F07-AB17-2A091DC7BC89} 8 | Library 9 | Properties 10 | UTT.Domain 11 | UTT.Domain 12 | v4.6.1 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\..\packages\FluentValidation.7.1.0\lib\net45\FluentValidation.dll 35 | 36 | 37 | ..\..\packages\MediatR.3.0.1\lib\net45\MediatR.dll 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/UTT.Domain/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/UTT.Domain.Tests/Customers/CustomerServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Threading; 3 | using FluentAssertions; 4 | using MediatR; 5 | using Moq; 6 | using Xunit; 7 | 8 | namespace UTT.Domain.Tests.Customers 9 | { 10 | [Collection(nameof(CustomerCollection))] 11 | public class CustomerServiceTests 12 | { 13 | public CustomerTestsFixture Fixture { get; set; } 14 | 15 | public CustomerServiceTests(CustomerTestsFixture fixture) 16 | { 17 | Fixture = fixture; 18 | } 19 | 20 | // AAA == Arrange, Act, Assert 21 | [Fact(DisplayName = "Register New Success")] 22 | [Trait("Category", "Customer Service Tests")] 23 | public void CustomerService_RegisterNew_ShouldRegisterWithSuccess() 24 | { 25 | // Arrange 26 | var customerService = Fixture.GetCustomerService(); 27 | var customer = Fixture.GetValidCustomer(); 28 | 29 | // Act 30 | customerService.Register(customer); 31 | 32 | // Assert 33 | Fixture.CustomerRepositoryMock.Verify(r => r.Add(customer), Times.Once); 34 | Fixture.MediatorMock.Verify(m => m.Publish(It.IsAny(), CancellationToken.None), Times.Once); 35 | } 36 | 37 | [Fact(DisplayName = "Register New Fail")] 38 | [Trait("Category", "Customer Service Tests")] 39 | public void CustomerService_RegisterNew_ShouldNotRegister() 40 | { 41 | // Arrange 42 | var customerService = Fixture.GetCustomerService(); 43 | var customer = Fixture.GetInvalidCustomer(); 44 | 45 | // Act 46 | customerService.Register(customer); 47 | 48 | // Assert 49 | Fixture.CustomerRepositoryMock.Verify(r => r.Add(customer), Times.Never); 50 | Fixture.MediatorMock.Verify(m => m.Publish(It.IsAny(), CancellationToken.None), Times.Never); 51 | } 52 | 53 | [Fact(DisplayName = "Get All Active Customers")] 54 | [Trait("Category", "Customer Service Tests")] 55 | public void CustomerService_GetAllActive_ShouldReturnsOnlyActiveCustomers() 56 | { 57 | // Arrange 58 | var customerService = Fixture.GetCustomerService(); 59 | Fixture.CustomerRepositoryMock.Setup(c => c.GetAll()).Returns(Fixture.GetMixedCustomers()); 60 | 61 | // Act 62 | var customers = customerService.GetAllActive().ToList(); 63 | 64 | // Assert Fluent Assertions 65 | customers.Should().HaveCount(c => c > 1).And.OnlyHaveUniqueItems(); 66 | customers.Should().NotContain(c => !c.Active); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /tests/UTT.Domain.Tests/Customers/CustomerTests.cs: -------------------------------------------------------------------------------- 1 | using FluentAssertions; 2 | using Xunit; 3 | 4 | namespace UTT.Domain.Tests.Customers 5 | { 6 | [Collection(nameof(CustomerCollection))] 7 | public class CustomerTests 8 | { 9 | public CustomerTestsFixture Fixture { get; set; } 10 | 11 | public CustomerTests(CustomerTestsFixture fixture) 12 | { 13 | Fixture = fixture; 14 | } 15 | 16 | // AAA == Arrange, Act, Assert 17 | [Fact(DisplayName = "New Customer Valid")] 18 | [Trait("Category", "Customer Tests")] 19 | public void Customer_NewCustomer_ShouldBeValid() 20 | { 21 | // Arrange 22 | var customer = Fixture.GetValidCustomer(); 23 | 24 | // Act 25 | var result = customer.IsValid(); 26 | 27 | // Assert Fluent Assertions (more expressive) 28 | result.Should().BeTrue(); 29 | customer.ValidationResult.Errors.Should().HaveCount(0); 30 | 31 | // Assert XUnit 32 | Assert.True(result); 33 | Assert.Equal(0, customer.ValidationResult.Errors.Count); 34 | } 35 | 36 | [Fact(DisplayName = "New Customer Invalid")] 37 | [Trait("Category", "Customer Tests")] 38 | public void Customer_NewCustomer_ShouldBeInvalid() 39 | { 40 | // Arrange 41 | var customer = Fixture.GetInvalidCustomer(); 42 | 43 | // Act 44 | var result = customer.IsValid(); 45 | 46 | // Assert Fluent Assertions (more expressive) 47 | result.Should().BeFalse(); 48 | customer.ValidationResult.Errors.Should().HaveCount(c=> c > 0); 49 | 50 | // Assert XUnit 51 | Assert.False(result); 52 | Assert.NotEqual(0, customer.ValidationResult.Errors.Count); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /tests/UTT.Domain.Tests/Customers/CustomerTestsFixture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using AutoMoq; 5 | using Bogus; 6 | using Bogus.DataSets; 7 | using MediatR; 8 | using Moq; 9 | using UTT.Domain.Customers; 10 | using UTT.Domain.Customers.Repository; 11 | using UTT.Domain.Customers.Services; 12 | using Xunit; 13 | 14 | namespace UTT.Domain.Tests.Customers 15 | { 16 | [CollectionDefinition(nameof(CustomerCollection))] 17 | public class CustomerCollection : ICollectionFixture 18 | { 19 | } 20 | 21 | public class CustomerTestsFixture : IDisposable 22 | { 23 | public Mock CustomerRepositoryMock { get; set; } 24 | public Mock CustomerServiceMock { get; set; } 25 | public Mock MediatorMock { get; set; } 26 | 27 | public CustomerService GetCustomerService() 28 | { 29 | var mocker = new AutoMoqer(); 30 | mocker.Create(); 31 | 32 | var customerService = mocker.Resolve(); 33 | 34 | CustomerRepositoryMock = mocker.GetMock(); 35 | CustomerServiceMock = mocker.GetMock(); 36 | MediatorMock = mocker.GetMock(); 37 | 38 | return customerService; 39 | } 40 | 41 | public Customer GetValidCustomer() 42 | { 43 | return GenerateCustomer(1, true).First(); 44 | } 45 | 46 | public Customer GetInvalidCustomer() 47 | { 48 | var customerTests = new Faker("pt-BR") 49 | .CustomInstantiator(f => new Customer( 50 | Guid.NewGuid(), 51 | f.Name.FirstName(Name.Gender.Male), 52 | f.Name.LastName(Name.Gender.Male), 53 | f.Date.Past(1, DateTime.Now.AddYears(1)), 54 | "", 55 | false, 56 | DateTime.Now)); 57 | 58 | return customerTests; 59 | } 60 | 61 | public IEnumerable GetMixedCustomers() 62 | { 63 | var customers = new List(); 64 | 65 | customers.AddRange(GenerateCustomer(50, true).ToList()); 66 | customers.AddRange(GenerateCustomer(50, false).ToList()); 67 | 68 | return customers; 69 | } 70 | 71 | private static IEnumerable GenerateCustomer(int number, bool isActive) 72 | { 73 | var customerTests = new Faker("pt-BR") 74 | .CustomInstantiator(f => new Customer( 75 | Guid.NewGuid(), 76 | f.Name.FirstName(Name.Gender.Male), 77 | f.Name.LastName(Name.Gender.Male), 78 | f.Date.Past(80, DateTime.Now.AddYears(-18)), 79 | f.Internet.Email().ToLower(), 80 | isActive, 81 | DateTime.Now)); 82 | 83 | return customerTests.Generate(number); 84 | } 85 | 86 | public void Dispose() 87 | { 88 | // Dispose what you have! 89 | } 90 | } 91 | } -------------------------------------------------------------------------------- /tests/UTT.Domain.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: AssemblyTitle("UTT.Domain.Tests")] 5 | [assembly: AssemblyDescription("")] 6 | [assembly: AssemblyConfiguration("")] 7 | [assembly: AssemblyCompany("")] 8 | [assembly: AssemblyProduct("UTT.Domain.Tests")] 9 | [assembly: AssemblyCopyright("Copyright © 2017")] 10 | [assembly: AssemblyTrademark("")] 11 | [assembly: AssemblyCulture("")] 12 | 13 | [assembly: ComVisible(false)] 14 | 15 | [assembly: Guid("830dbd32-dbc9-4181-b672-6f3384d056f8")] 16 | 17 | // [assembly: AssemblyVersion("1.0.*")] 18 | [assembly: AssemblyVersion("1.0.0.0")] 19 | [assembly: AssemblyFileVersion("1.0.0.0")] 20 | -------------------------------------------------------------------------------- /tests/UTT.Domain.Tests/UTT.Domain.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {830DBD32-DBC9-4181-B672-6F3384D056F8} 8 | Library 9 | Properties 10 | UTT.Domain.Tests 11 | UTT.Domain.Tests 12 | v4.6.1 13 | 512 14 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15 | 15.0 16 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 17 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 18 | False 19 | UnitTest 20 | 21 | 22 | 23 | 24 | true 25 | full 26 | false 27 | bin\Debug\ 28 | DEBUG;TRACE 29 | prompt 30 | 4 31 | 32 | 33 | pdbonly 34 | true 35 | bin\Release\ 36 | TRACE 37 | prompt 38 | 4 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | {AEC738F7-D84B-4F07-AB17-2A091DC7BC89} 53 | UTT.Domain 54 | 55 | 56 | 57 | 58 | ..\..\packages\AutoMoq.2.0.0\lib\net45\AutoMoq.dll 59 | 60 | 61 | ..\..\packages\Bogus.15.0.3\lib\net40\Bogus.dll 62 | 63 | 64 | ..\..\packages\Castle.Core.4.1.1\lib\net45\Castle.Core.dll 65 | 66 | 67 | ..\..\packages\FluentAssertions.4.19.3\lib\net45\FluentAssertions.dll 68 | 69 | 70 | ..\..\packages\FluentAssertions.4.19.3\lib\net45\FluentAssertions.Core.dll 71 | 72 | 73 | ..\..\packages\FluentValidation.7.1.0\lib\net45\FluentValidation.dll 74 | 75 | 76 | ..\..\packages\MediatR.3.0.1\lib\net45\MediatR.dll 77 | 78 | 79 | ..\..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll 80 | 81 | 82 | ..\..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.dll 83 | 84 | 85 | ..\..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.Configuration.dll 86 | 87 | 88 | ..\..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.RegistrationByConvention.dll 89 | 90 | 91 | ..\..\packages\Moq.4.7.99\lib\net45\Moq.dll 92 | 93 | 94 | ..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll 95 | 96 | 97 | 98 | 99 | ..\..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll 100 | 101 | 102 | ..\..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll 103 | 104 | 105 | ..\..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll 106 | 107 | 108 | ..\..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll 109 | 110 | 111 | ..\..\packages\xunit.extensions.1.9.0.1566\lib\xunit.extensions.dll 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /tests/UTT.Domain.Tests/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/UTT.Domain.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | --------------------------------------------------------------------------------