diff --git a/README.md b/README.md index 4851392..f0b394d 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ Prior to v2.0 this library was known as NTestDataBuilder. } } +Note that overriding the BuildObject is optional. It can be useful to do this if you want full control over how your object is constructed, for example if you want to use a particular constructor. If you don't choose to override this method then Dossier will create the object for you. 3. Use the builder in a test, e.g. diff --git a/TestStack.Dossier.Tests/BuildListTests.cs b/TestStack.Dossier.Tests/BuildListTests.cs index 2b498db..e2651b2 100644 --- a/TestStack.Dossier.Tests/BuildListTests.cs +++ b/TestStack.Dossier.Tests/BuildListTests.cs @@ -4,7 +4,7 @@ using TestStack.Dossier.DataSources.Generators; using TestStack.Dossier.Lists; using TestStack.Dossier.Tests.Builders; -using TestStack.Dossier.Tests.Entities; +using TestStack.Dossier.Tests.Stubs.Entities; using Xunit; namespace TestStack.Dossier.Tests @@ -70,16 +70,7 @@ public void GivenListOfBuilders_WhenCallingBuildListExplicitly_ThenAListOfUnique var entities = builders.BuildList(); - entities[0].ShouldNotBe(entities[1]); - entities[0].ShouldNotBe(entities[2]); - entities[0].ShouldNotBe(entities[3]); - entities[0].ShouldNotBe(entities[4]); - entities[1].ShouldNotBe(entities[2]); - entities[1].ShouldNotBe(entities[3]); - entities[1].ShouldNotBe(entities[4]); - entities[2].ShouldNotBe(entities[3]); - entities[2].ShouldNotBe(entities[4]); - entities[3].ShouldNotBe(entities[4]); + entities.ShouldBeUnique(); } [Fact] @@ -87,16 +78,7 @@ public void GivenListOfBuilders_WhenCallingBuildListImplicitly_ThenAListOfUnique { List entities = BasicCustomerBuilder.CreateListOfSize(5); - entities[0].ShouldNotBe(entities[1]); - entities[0].ShouldNotBe(entities[2]); - entities[0].ShouldNotBe(entities[3]); - entities[0].ShouldNotBe(entities[4]); - entities[1].ShouldNotBe(entities[2]); - entities[1].ShouldNotBe(entities[3]); - entities[1].ShouldNotBe(entities[4]); - entities[2].ShouldNotBe(entities[3]); - entities[2].ShouldNotBe(entities[4]); - entities[3].ShouldNotBe(entities[4]); + entities.ShouldBeUnique(); } [Fact] diff --git a/TestStack.Dossier.Tests/BuildTests.cs b/TestStack.Dossier.Tests/BuildTests.cs index c2fcdf6..f6088aa 100644 --- a/TestStack.Dossier.Tests/BuildTests.cs +++ b/TestStack.Dossier.Tests/BuildTests.cs @@ -1,6 +1,6 @@ using Shouldly; using TestStack.Dossier.Tests.Builders; -using TestStack.Dossier.Tests.Entities; +using TestStack.Dossier.Tests.Stubs.Entities; using Xunit; namespace TestStack.Dossier.Tests @@ -80,5 +80,19 @@ public void GivenBuilder_WhenCallingSetImplicitly_ShouldOverrideValues() customer.LastName.ShouldBe("Lanningham"); customer.YearJoined.ShouldBe(2014); } + + [Fact] + public void GivenBuilderUsingConstructorReflection_WhenCallingBuildExplicitly_ShouldOverrideValues() + { + Customer customer = new AutoConstructorCustomerBuilder() + .WithFirstName("Bruce") + .WithLastName("Wayne") + .WhoJoinedIn(2012) + .Build(); + + customer.FirstName.ShouldBe("Bruce"); + customer.LastName.ShouldBe("Wayne"); + customer.YearJoined.ShouldBe(2012); + } } } \ No newline at end of file diff --git a/TestStack.Dossier.Tests/BuilderBuildListTests.cs b/TestStack.Dossier.Tests/BuilderBuildListTests.cs new file mode 100644 index 0000000..458e112 --- /dev/null +++ b/TestStack.Dossier.Tests/BuilderBuildListTests.cs @@ -0,0 +1,171 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Shouldly; +using TestStack.Dossier.DataSources.Generators; +using TestStack.Dossier.Lists; +using TestStack.Dossier.Tests.Builders; +using TestStack.Dossier.Tests.Stubs.ViewModels; +using Xunit; + +namespace TestStack.Dossier.Tests +{ + public class BuilderBuildListTests + { + private DateTime _enrollmentDate = new DateTime(2004, 9, 9); + + [Fact] + public void GivenANormalBuilderInstance_WhenCallingIsListBuilderProxy_ThenReturnFalse() + { + var builder = Builder.CreateNew(); + + builder.IsListBuilderProxy().ShouldBe(false); + } + + [Fact] + public void GivenAListBuilderProxyInstance_WhenCallingIsListBuilderProxy_ThenReturnTrue() + { + var builder = Builder.CreateListOfSize(1).TheFirst(1); + + builder.IsListBuilderProxy().ShouldBe(true); + } + + [Fact] + public void GivenListOfBuilders_WhenCallingBuildListExplicitly_ThenAListOfEntitiesOfTheRightSizeShouldBeReturned() + { + var builders = Builder.CreateListOfSize(5); + + var entities = builders.BuildList(); + + entities.Count.ShouldBe(5); + } + + [Fact] + public void GivenListOfBuilders_WhenCallingBuildListImplicitly_ThenAListOfEntitiesOfTheRightSizeShouldBeReturned() + { + List entities = Builder.CreateListOfSize(5); + + entities.Count.ShouldBe(5); + } + + [Fact] + public void GivenListOfBuilders_WhenCallingBuildListExplicitly_ThenAListOfEntitiesOfTheRightTypeShouldBeReturned() + { + var builders = Builder.CreateListOfSize(5); + + var entities = builders.BuildList(); + + entities.ShouldBeAssignableTo>(); + } + + [Fact] + public void GivenListOfBuilders_WhenCallingBuildListImplicitly_ThenAListOfEntitiesOfTheRightTypeShouldBeReturned() + { + List entities = Builder.CreateListOfSize(5); + + entities.ShouldBeAssignableTo>(); + } + + [Fact] + public void GivenListOfBuilders_WhenCallingBuildListExplicitly_ThenAListOfUniqueEntitiesShouldBeReturned() + { + var builders = Builder.CreateListOfSize(5); + + var entities = builders.BuildList(); + + entities.ShouldBeUnique(); + } + + [Fact] + public void GivenListOfBuilders_WhenCallingBuildListImplicitly_ThenAListOfUniqueEntitiesShouldBeReturned() + { + List entities = Builder.CreateListOfSize(5); + + entities.ShouldBeUnique(); + } + + [Fact] + public void GivenListOfBuildersWithCustomisation_WhenBuildingEntitiesExplicitly_ThenTheCustomisationShouldTakeEffect() + { + var generator = new SequentialGenerator(0, 100); + var list = StudentViewModelBuilder.CreateListOfSize(3) + .All().With(b => b.WithFirstName(generator.Generate().ToString())); + + var data = list.BuildList(); + + data.Select(c => c.FirstName).ToArray() + .ShouldBe(new[] { "0", "1", "2" }); + } + + [Fact] + public void GivenListOfBuildersWithCustomisation_WhenBuildingEntitiesImplicitly_ThenTheCustomisationShouldTakeEffect() + { + var generator = new SequentialGenerator(0, 100); + + List data = StudentViewModelBuilder.CreateListOfSize(3) + .All().With(b => b.WithFirstName(generator.Generate().ToString())); + + data.Select(c => c.FirstName).ToArray() + .ShouldBe(new[] { "0", "1", "2" }); + } + + [Fact] + public void GivenListOfBuildersWithARangeOfCustomisationMethods_WhenBuildingEntitiesExplicitly_ThenThenTheListIsBuiltAndModifiedCorrectly() + { + var i = 0; + var studentViewModels = StudentViewModelBuilder.CreateListOfSize(5) + .TheFirst(1).WithFirstName("First") + .TheNext(1).WithLastName("Next Last") + .TheLast(1).WithLastName("Last Last") + .ThePrevious(2).With(b => b.WithLastName("last" + (++i).ToString())) + .All().WhoEntrolledIn(_enrollmentDate) + .BuildList(); + + studentViewModels.ShouldBeAssignableTo>(); + studentViewModels.Count.ShouldBe(5); + studentViewModels[0].FirstName.ShouldBe("First"); + studentViewModels[1].LastName.ShouldBe("Next Last"); + studentViewModels[2].LastName.ShouldBe("last1"); + studentViewModels[3].LastName.ShouldBe("last2"); + studentViewModels[4].LastName.ShouldBe("Last Last"); + studentViewModels.ShouldAllBe(c => c.EnrollmentDate == _enrollmentDate); + } + + [Fact] + public void GivenListOfBuildersWithARangeOfCustomisationMethods_WhenBuildingEntitiesImplicitly_ThenThenTheListIsBuiltAndModifiedCorrectly() + { + var i = 0; + List studentViewModels = StudentViewModelBuilder.CreateListOfSize(5) + .TheFirst(1).WithFirstName("First") + .TheNext(1).WithLastName("Next Last") + .TheLast(1).WithLastName("Last Last") + .ThePrevious(2).With(b => b.WithLastName("last" + (++i).ToString())) + .All().WhoEntrolledIn(_enrollmentDate); + + studentViewModels.ShouldBeAssignableTo>(); + studentViewModels.Count.ShouldBe(5); + studentViewModels[0].FirstName.ShouldBe("First"); + studentViewModels[1].LastName.ShouldBe("Next Last"); + studentViewModels[2].LastName.ShouldBe("last1"); + studentViewModels[3].LastName.ShouldBe("last2"); + studentViewModels[4].LastName.ShouldBe("Last Last"); + studentViewModels.ShouldAllBe(c => c.EnrollmentDate == _enrollmentDate); + } + + [Fact] + public void WhenBuildingEntitiesExplicitly_ThenTheAnonymousValueFixtureIsSharedAcrossBuilders() + { + var studentViewModels = StudentViewModelBuilder.CreateListOfSize(5).BuildList(); + + studentViewModels.Select(x => x.Grade).ShouldBeUnique(); + } + + [Fact] + public void WhenBuildingEntitiesImplicitly_ThenTheAnonymousValueFixtureIsSharedAcrossBuilders() + { + List studentViewModels = StudentViewModelBuilder.CreateListOfSize(5); + + studentViewModels.Select(x => x.Grade).ShouldBeUnique(); + } + } +} \ No newline at end of file diff --git a/TestStack.Dossier.Tests/BuilderBuildTests.cs b/TestStack.Dossier.Tests/BuilderBuildTests.cs new file mode 100644 index 0000000..87530a8 --- /dev/null +++ b/TestStack.Dossier.Tests/BuilderBuildTests.cs @@ -0,0 +1,72 @@ +using System; +using Shouldly; +using TestStack.Dossier.Tests.Builders; +using TestStack.Dossier.Tests.Stubs.Entities; +using TestStack.Dossier.Tests.Stubs.ViewModels; +using Xunit; + +namespace TestStack.Dossier.Tests +{ + public class BuilderBuildTests + { + [Fact] + public void GivenBasicBuilder_WhenCallingBuildExplicitly_ThenReturnAnObject() + { + var builder = Builder.CreateNew(); + + var customer = builder.Build(); + + customer.ShouldBeOfType(); + } + + [Fact] + public void GivenBuilder_WhenCallingSetExplicitly_ShouldOverrideValues() + { + var builder = Builder.CreateNew() + .Set(x => x.FirstName, "Pi") + .Set(x => x.LastName, "Lanningham") + .Set(x => x.YearJoined, 2014); + + var customer = builder.Build(); + + customer.FirstName.ShouldBe("Pi"); + customer.LastName.ShouldBe("Lanningham"); + customer.YearJoined.ShouldBe(2014); + } + + [Fact] + public void GivenBasicBuilder_WhenCallingBuildImplicitly_ThenReturnAnObject() + { + Customer customer = Builder.CreateNew(); + + customer.ShouldBeOfType(); + } + + [Fact] + public void GivenBuilder_WhenCallingSetImplicitly_ShouldOverrideValues() + { + Customer customer = Builder.CreateNew() + .Set(x => x.FirstName, "Pi") + .Set(x => x.LastName, "Lanningham") + .Set(x => x.YearJoined, 2014); + + customer.FirstName.ShouldBe("Pi"); + customer.LastName.ShouldBe("Lanningham"); + customer.YearJoined.ShouldBe(2014); + } + + [Fact] + public void GivenBuilder_WhenBuildingObjectWithCtorAndPrivateSetters_ShouldSetPrivateSetters() + { + var id = Guid.NewGuid(); + InstructorViewModel instructor = Builder.CreateNew() + .Set(x => x.FirstName, "Pi") + .Set(x => x.LastName, "Lanningham") + .Set(x => x.Id, id); + + instructor.FirstName.ShouldBe("Pi"); + instructor.LastName.ShouldBe("Lanningham"); + instructor.Id.ShouldBe(id); + } + } +} \ No newline at end of file diff --git a/TestStack.Dossier.Tests/Builders/AutoConstructorCustomerBuilder.cs b/TestStack.Dossier.Tests/Builders/AutoConstructorCustomerBuilder.cs new file mode 100644 index 0000000..15d37ba --- /dev/null +++ b/TestStack.Dossier.Tests/Builders/AutoConstructorCustomerBuilder.cs @@ -0,0 +1,28 @@ +using TestStack.Dossier.Factories; +using TestStack.Dossier.Tests.Stubs.Entities; + +namespace TestStack.Dossier.Tests.Builders +{ + class AutoConstructorCustomerBuilder : TestDataBuilder + { + public AutoConstructorCustomerBuilder WithFirstName(string firstName) + { + return Set(x => x.FirstName, firstName); + } + + public AutoConstructorCustomerBuilder WithLastName(string lastName) + { + return Set(x => x.LastName, lastName); + } + + public AutoConstructorCustomerBuilder WhoJoinedIn(int year) + { + return Set(x => x.YearJoined, year); + } + + protected override Customer BuildObject() + { + return BuildUsing(); + } + } +} diff --git a/TestStack.Dossier.Tests/Builders/BasicCustomerBuilder.cs b/TestStack.Dossier.Tests/Builders/BasicCustomerBuilder.cs index df39128..dc6462f 100644 --- a/TestStack.Dossier.Tests/Builders/BasicCustomerBuilder.cs +++ b/TestStack.Dossier.Tests/Builders/BasicCustomerBuilder.cs @@ -1,6 +1,6 @@ using System; using System.Linq.Expressions; -using TestStack.Dossier.Tests.Entities; +using TestStack.Dossier.Tests.Stubs.Entities; namespace TestStack.Dossier.Tests.Builders { diff --git a/TestStack.Dossier.Tests/Builders/CustomerBuilder.cs b/TestStack.Dossier.Tests/Builders/CustomerBuilder.cs index 96e133c..319a57c 100644 --- a/TestStack.Dossier.Tests/Builders/CustomerBuilder.cs +++ b/TestStack.Dossier.Tests/Builders/CustomerBuilder.cs @@ -1,4 +1,4 @@ -using TestStack.Dossier.Tests.Entities; +using TestStack.Dossier.Tests.Stubs.Entities; namespace TestStack.Dossier.Tests.Builders { diff --git a/TestStack.Dossier.Tests/Builders/ProxyAlteringCustomerBuilder.cs b/TestStack.Dossier.Tests/Builders/ProxyAlteringCustomerBuilder.cs index 9272dd4..2419fdf 100644 --- a/TestStack.Dossier.Tests/Builders/ProxyAlteringCustomerBuilder.cs +++ b/TestStack.Dossier.Tests/Builders/ProxyAlteringCustomerBuilder.cs @@ -1,6 +1,6 @@ using System; using NSubstitute; -using TestStack.Dossier.Tests.Entities; +using TestStack.Dossier.Tests.Stubs.Entities; namespace TestStack.Dossier.Tests.Builders { diff --git a/TestStack.Dossier.Tests/Builders/StudentViewModelBuilder.cs b/TestStack.Dossier.Tests/Builders/StudentViewModelBuilder.cs new file mode 100644 index 0000000..d57a028 --- /dev/null +++ b/TestStack.Dossier.Tests/Builders/StudentViewModelBuilder.cs @@ -0,0 +1,29 @@ +using System; +using TestStack.Dossier.Factories; +using TestStack.Dossier.Tests.Stubs.ViewModels; + +namespace TestStack.Dossier.Tests.Builders +{ + public class StudentViewModelBuilder : TestDataBuilder + { + public virtual StudentViewModelBuilder WithFirstName(string firstName) + { + return Set(x => x.FirstName, firstName); + } + + public virtual StudentViewModelBuilder WithLastName(string lastName) + { + return Set(x => x.LastName, lastName); + } + + public virtual StudentViewModelBuilder WhoEntrolledIn(DateTime enrollmentDate) + { + return Set(x => x.EnrollmentDate, enrollmentDate); + } + + protected override StudentViewModel BuildObject() + { + return BuildUsing(); + } + } +} diff --git a/TestStack.Dossier.Tests/Factories/FactoryTests.cs b/TestStack.Dossier.Tests/Factories/FactoryTests.cs new file mode 100644 index 0000000..c90dc01 --- /dev/null +++ b/TestStack.Dossier.Tests/Factories/FactoryTests.cs @@ -0,0 +1,88 @@ +using System; +using Shouldly; +using TestStack.Dossier.Factories; +using TestStack.Dossier.Tests.Stubs.Entities; +using TestStack.Dossier.Tests.Stubs.ViewModels; +using Xunit; + +namespace TestStack.Dossier.Tests.Factories +{ + public class FactoryTests + { + [Fact] + public void GivenAllPropertiesFactory_WhenBuilding_ThenAllPropertiesSet() + { + InstructorViewModel instructor = Builder.CreateNew(new AllPropertiesFactory()); + + // ctor properties + instructor.Id.ShouldNotBe(Guid.Empty); + instructor.FirstName.ShouldNotBe(null); + instructor.LastName.ShouldNotBe(null); + + // public properties + instructor.Room.ShouldNotBe(null); + instructor.NumberOfStudents.ShouldNotBe(0); + + // private properties + instructor.Subject.ShouldNotBe(null); + instructor.YearsAtSchool.ShouldNotBe(0); + } + + [Fact] + public void GivenAutoFixtureFactory_WhenBuilding_ThenOnlyConstructorAndPublicPropertiesSet() + { + InstructorViewModel instructor = Builder.CreateNew(new AutoFixtureFactory()); + + // ctor properties + instructor.Id.ShouldNotBe(Guid.Empty); + instructor.FirstName.ShouldNotBe(null); + instructor.LastName.ShouldNotBe(null); + + // public properties + instructor.Room.ShouldNotBe(null); + instructor.NumberOfStudents.ShouldNotBe(0); + + // private properties + instructor.Subject.ShouldBe(null); + instructor.YearsAtSchool.ShouldBe(0); + } + + [Fact] + public void GivenConstructorPropertiesFactory_WhenBuilding_ThenOnlyConstructorPropertiesSet() + { + InstructorViewModel instructor = Builder.CreateNew(new ConstructorFactory()); + + // ctor properties + instructor.Id.ShouldNotBe(Guid.Empty); + instructor.FirstName.ShouldNotBe(null); + instructor.LastName.ShouldNotBe(null); + + // public properties + instructor.Room.ShouldBe(null); + instructor.NumberOfStudents.ShouldBe(0); + + // private properties + instructor.Subject.ShouldBe(null); + instructor.YearsAtSchool.ShouldBe(0); + } + + [Fact] + public void GivenPublicPropertiesFactory_WhenBuilding_ThenOnlyConstructorAndPublicPropertiesSet() + { + InstructorViewModel instructor = Builder.CreateNew(new PublicPropertiesFactory()); + + // ctor properties + instructor.Id.ShouldNotBe(Guid.Empty); + instructor.FirstName.ShouldNotBe(null); + instructor.LastName.ShouldNotBe(null); + + // public properties + instructor.Room.ShouldNotBe(null); + instructor.NumberOfStudents.ShouldBeGreaterThan(0); + + // private properties + instructor.Subject.ShouldBe(null); + instructor.YearsAtSchool.ShouldBe(0); + } + } +} diff --git a/TestStack.Dossier.Tests/GetAnonymousTests.cs b/TestStack.Dossier.Tests/GetAnonymousTests.cs index 442b556..c415c73 100644 --- a/TestStack.Dossier.Tests/GetAnonymousTests.cs +++ b/TestStack.Dossier.Tests/GetAnonymousTests.cs @@ -1,4 +1,5 @@ -using Shouldly; +using System; +using Shouldly; using TestStack.Dossier.DataSources.Person; using TestStack.Dossier.Lists; using TestStack.Dossier.Tests.Builders; @@ -113,9 +114,20 @@ public bool CanSupplyValue(string propertyName) && propertyName.ToLower().StartsWith("year"); } + public bool CanSupplyValue(Type type, string propertyName) + { + return type == typeof(int) + && propertyName.ToLower().StartsWith("year"); + } + public TValue GenerateAnonymousValue(AnonymousValueFixture any, string propertyName) { return (TValue)(object)_year++; } + + public object GenerateAnonymousValue(AnonymousValueFixture any, Type type, string propertyName) + { + return _year++; + } } } diff --git a/TestStack.Dossier.Tests/ProxyBuilderTests.cs b/TestStack.Dossier.Tests/ProxyBuilderTests.cs index e7aa540..ae9aef8 100644 --- a/TestStack.Dossier.Tests/ProxyBuilderTests.cs +++ b/TestStack.Dossier.Tests/ProxyBuilderTests.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using NSubstitute; using Shouldly; -using TestStack.Dossier.Tests.Entities; +using TestStack.Dossier.Tests.Stubs.Entities; using Xunit; namespace TestStack.Dossier.Tests diff --git a/TestStack.Dossier.Tests/Entities/Company.cs b/TestStack.Dossier.Tests/Stubs/Entities/Company.cs similarity index 86% rename from TestStack.Dossier.Tests/Entities/Company.cs rename to TestStack.Dossier.Tests/Stubs/Entities/Company.cs index 4e2dfbe..2635100 100644 --- a/TestStack.Dossier.Tests/Entities/Company.cs +++ b/TestStack.Dossier.Tests/Stubs/Entities/Company.cs @@ -1,4 +1,4 @@ -namespace TestStack.Dossier.Tests.Entities +namespace TestStack.Dossier.Tests.Stubs.Entities { public class Company { diff --git a/TestStack.Dossier.Tests/Entities/Customer.cs b/TestStack.Dossier.Tests/Stubs/Entities/Customer.cs similarity index 95% rename from TestStack.Dossier.Tests/Entities/Customer.cs rename to TestStack.Dossier.Tests/Stubs/Entities/Customer.cs index 5796b0d..0e71270 100644 --- a/TestStack.Dossier.Tests/Entities/Customer.cs +++ b/TestStack.Dossier.Tests/Stubs/Entities/Customer.cs @@ -1,6 +1,6 @@ -using System; +using System; -namespace TestStack.Dossier.Tests.Entities +namespace TestStack.Dossier.Tests.Stubs.Entities { public class Customer { diff --git a/TestStack.Dossier.Tests/Entities/CustomerClass.cs b/TestStack.Dossier.Tests/Stubs/Entities/CustomerClass.cs similarity index 70% rename from TestStack.Dossier.Tests/Entities/CustomerClass.cs rename to TestStack.Dossier.Tests/Stubs/Entities/CustomerClass.cs index 81f3956..dd79d7b 100644 --- a/TestStack.Dossier.Tests/Entities/CustomerClass.cs +++ b/TestStack.Dossier.Tests/Stubs/Entities/CustomerClass.cs @@ -1,4 +1,4 @@ -namespace TestStack.Dossier.Tests.Entities +namespace TestStack.Dossier.Tests.Stubs.Entities { public enum CustomerClass { diff --git a/TestStack.Dossier.Tests/Stubs/ViewModels/Grade.cs b/TestStack.Dossier.Tests/Stubs/ViewModels/Grade.cs new file mode 100644 index 0000000..8598bb2 --- /dev/null +++ b/TestStack.Dossier.Tests/Stubs/ViewModels/Grade.cs @@ -0,0 +1,7 @@ +namespace TestStack.Dossier.Tests.Stubs.ViewModels +{ + public enum Grade + { + A, B, C, D, F + } +} \ No newline at end of file diff --git a/TestStack.Dossier.Tests/Stubs/ViewModels/InstructorViewModel.cs b/TestStack.Dossier.Tests/Stubs/ViewModels/InstructorViewModel.cs new file mode 100644 index 0000000..b0db3e9 --- /dev/null +++ b/TestStack.Dossier.Tests/Stubs/ViewModels/InstructorViewModel.cs @@ -0,0 +1,32 @@ +using System; + +namespace TestStack.Dossier.Tests.Stubs.ViewModels +{ + public class InstructorViewModel + { + public InstructorViewModel(Guid id, string firstName, string lastName) + { + Id = id; + FirstName = firstName; + LastName = lastName; + } + + public Guid Id { get; private set; } + + public string LastName { get; set; } + public string FirstName { get; private set; } + + public string FullName + { + get + { + return FirstName + " " + LastName; + } + } + public string Room{ get; set; } + + public string Subject{ get; private set; } + public int YearsAtSchool { get; private set; } + public int NumberOfStudents { get; set; } + } +} diff --git a/TestStack.Dossier.Tests/Stubs/ViewModels/StudentViewModel.cs b/TestStack.Dossier.Tests/Stubs/ViewModels/StudentViewModel.cs new file mode 100644 index 0000000..674a844 --- /dev/null +++ b/TestStack.Dossier.Tests/Stubs/ViewModels/StudentViewModel.cs @@ -0,0 +1,35 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace TestStack.Dossier.Tests.Stubs.ViewModels +{ + public class StudentViewModel + { + public int Id { get; set; } + + [Required] + [StringLength(50)] + [Display(Name = "Last Name")] + public string LastName { get; set; } + [Required] + [StringLength(50, ErrorMessage = "First name cannot be longer than 50 characters.")] + [Display(Name = "First Name")] + public string FirstName { get; set; } + + [Display(Name = "Full Name")] + public string FullName + { + get + { + return FirstName + " " + LastName; + } + } + + [DataType(DataType.Date)] + [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)] + [Display(Name = "Enrollment Date")] + public DateTime EnrollmentDate { get; set; } + + public Grade Grade { get; set; } + } +} diff --git a/TestStack.Dossier.Tests/TestHelpers/StaticAnonymousValueSupplier.cs b/TestStack.Dossier.Tests/TestHelpers/StaticAnonymousValueSupplier.cs index dc3db91..4c7c9a0 100644 --- a/TestStack.Dossier.Tests/TestHelpers/StaticAnonymousValueSupplier.cs +++ b/TestStack.Dossier.Tests/TestHelpers/StaticAnonymousValueSupplier.cs @@ -1,4 +1,6 @@ -namespace TestStack.Dossier.Tests.TestHelpers +using System; + +namespace TestStack.Dossier.Tests.TestHelpers { public class StaticAnonymousValueSupplier : IAnonymousValueSupplier { @@ -14,9 +16,19 @@ public bool CanSupplyValue(string propertyName) return typeof(TValue) == _valueToSupply.GetType(); } + public bool CanSupplyValue(Type type, string propertyName) + { + return type == _valueToSupply.GetType(); + } + public TValue GenerateAnonymousValue(AnonymousValueFixture any, string propertyName) { return (TValue) _valueToSupply; } + + public object GenerateAnonymousValue(AnonymousValueFixture any, Type type, string propertyName) + { + return _valueToSupply; + } } } diff --git a/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj b/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj index 73d099b..ac4666b 100644 --- a/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj +++ b/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj @@ -13,7 +13,7 @@ 512 ..\ - d4853673 + 660882d1 true @@ -44,6 +44,7 @@ ..\packages\Shouldly.2.4.0\lib\net40\Shouldly.dll + @@ -54,8 +55,15 @@ + + + + - + + + + @@ -75,13 +83,14 @@ - - + + + @@ -89,17 +98,20 @@ Designer + + + PreserveNewest + + + + + {01e4ee61-ab1a-4177-8b6c-d50205d167a9} TestStack.Dossier - - - PreserveNewest - -