public void PersonController_Get_ReturnPersons() { using (DatabaseContext databaseContext = DatabaseTestFactory.GetSession()) { var person01 = PersonAggregate.Create("John", "Smith"); var person02 = PersonAggregate.Create("Mary", "Jane"); databaseContext.Set <PersonAggregate>().AddRange(new[] { person01, person02 }); databaseContext.SaveChanges(); } using (WebApp.Start <Startup>(url: iisAddress)) { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); var response = client.GetAsync(String.Format("{0}PersonRead", iisAddress)).Result; response.StatusCode.Should().Be(HttpStatusCode.OK); var result = response.Content.ReadAsStringAsync().Result; Debug.WriteLine(response.Content.ReadAsStringAsync().Result); var persons = JsonConvert.DeserializeObject <PersonMessage[]>(result); persons.Should() .ContainSingle(x => x.FirstName == "John" && x.LastName == "Smith"); persons.Should() .ContainSingle(x => x.FirstName == "Mary" && x.LastName == "Jane"); } }
public static PersonAggregate Person() { var person = PersonAggregate.Create("John", "Smith"); person.AddAddress("Main Street", "New York", "USA", "11100"); return(person); }
public void PersonAggregate_Delete_WithAddresses_WillCascade() { /// create using (DatabaseContext databaseContext = DatabaseTestFactory.GetSession()) { var person = PersonAggregate.Create("John", "Smith"); person.AddAddress("Street", "City", "Country", "ZipCode"); databaseContext.Set <PersonAggregate>().Add(person); databaseContext.SaveChanges(); } /// delete using (DatabaseContext databaseContext = DatabaseTestFactory.GetSession()) { var person = databaseContext.Set <PersonAggregate>().First(); databaseContext.Set <PersonAggregate>().Remove(person); databaseContext.SaveChanges(); } /// verify using (DatabaseContext databaseContext = DatabaseTestFactory.GetSession()) { databaseContext.Set <PersonAggregate>().Count().Should().Be(0); databaseContext.Set <Address>().Count().Should().Be(0); } }
public void PersonAggregate_Create_HasEmptyAddress() { var person = PersonAggregate.Create("John", "Smith"); person.Addresses.Should().NotBeNull(); person.Addresses.Should().BeEmpty(); }
public void Address_Create_ValidValues_IsValid() { var person = PersonAggregate.Create("John", "Smith"); var address = Address.Create(person, "Street", "City", "Country", "ZipCode"); address.IsValid.Should().BeTrue(); }
public void PersonAggregate_Add_InvalidAddress_Fail() { var person = PersonAggregate.Create("John", "Smith"); person.AddAddress(string.Empty, string.Empty, string.Empty, string.Empty); person.Addresses.Should().BeEmpty(); }
public void PersonAggregate_Add_ValidAddress_WillContain() { var person = PersonAggregate.Create("John", "Smith"); person.AddAddress("Street", "City", "Country", "ZipCode"); person.Addresses.Should().NotBeEmpty(); person.Addresses.Count.Should().Be(1); }
public static PersonAggregate Create(string id, string name) { var agg = new PersonAggregate(new PersonAggregateState()); agg.Create(new RegisterPerson() { Id = id, Name = name }); return(agg); }
public HttpResponseMessage Post(PersonMessage person) { using (DatabaseContext databaseContext = new DatabaseContext()) { var personAggregate = PersonAggregate.Create( person.FirstName, person.LastName); databaseContext.Set <PersonAggregate>().Add(personAggregate); databaseContext.SaveChanges(); var response = Request.CreateResponse(HttpStatusCode.Created, personAggregate.Id); return(response); } }
public static PersonAggregate CreateWithUncommitedUpdates(string id, int nrOfUpdates) { var p = new PersonAggregate(new PersonAggregateState()); p.Create(new RegisterPerson() { Id = id, Name = "0" }); for (int i = 0; i < nrOfUpdates; i++) { p.Rename(new RenamePerson() { Id = id, Name = $"Name {i + 1}" }); } return(p); }
public void PersonAggregate_Valid_CanBeCreated() { /// create using (DatabaseContext databaseContext = DatabaseTestFactory.GetSession()) { var person = PersonAggregate.Create("FirstName", "LastName"); databaseContext.Set <PersonAggregate>().Add(person); databaseContext.SaveChanges(); } /// verify using (DatabaseContext databaseContext = DatabaseTestFactory.GetSession()) { var expectedPerson = databaseContext.Set <PersonAggregate>().First(); expectedPerson.FirstName.Should().Be("FirstName"); expectedPerson.LastName.Should().Be("LastName"); } }
public void PersonAggregate_AddAddress_WillContain() { /// create using (DatabaseContext databaseContext = DatabaseTestFactory.GetSession()) { var person = PersonAggregate.Create("John", "Smith"); person.AddAddress("Street", "City", "Country", "ZipCode"); databaseContext.Set <PersonAggregate>().Add(person); databaseContext.SaveChanges(); } /// verify using (DatabaseContext databaseContext = DatabaseTestFactory.GetSession()) { var person = databaseContext.Set <PersonAggregate>() .Include(x => x.Addresses).First(); person.Addresses.Count.Should().Be(1); } }
public void PersonAggregate_Create_ValidValues_IsValid() { var person = PersonAggregate.Create("John", "Smith"); person.IsValid.Should().BeTrue(); }
public void PersonAggregate_Created_EmptyValues_IsNotValid() { var person = PersonAggregate.Create(string.Empty, string.Empty); person.IsValid.Should().BeFalse(); }