Exemplo n.º 1
0
        public void Delete_GivenPoco_ShouldDeletePoco()
        {
            // Arrange
            DB.Insert(_person);
            _order.PersonId = _person.Id;
            DB.Insert(_order);
            _orderLine.OrderId = _order.Id;
            DB.Insert(_orderLine);
            DB.Insert(_note);

            // Act
            DB.Delete(_orderLine);
            DB.Delete(_order);
            DB.Delete(_person);
            DB.Delete(_note);

            _person = DB.SingleOrDefault<Person>(_person.Id);
            _order = DB.SingleOrDefault<Order>(_order.Id);
            _orderLine = DB.SingleOrDefault<OrderLine>(_orderLine.Id);
            _note = DB.SingleOrDefault<Note>(_note.Id);

            // Assert
            _person.ShouldBeNull();
            _order.ShouldBeNull();
            _orderLine.ShouldBeNull();
            _note.ShouldBeNull();
        }
Exemplo n.º 2
0
 public void ShouldBe(Person other)
 {
     Id.ShouldBe(other.Id);
     Name.ShouldBe(other.Name);
     Age.ShouldBe(other.Age);
     Height.ShouldBe(other.Height);
     Dob.ShouldBe(other.Dob);
 }
Exemplo n.º 3
0
 public void ShouldNotBe(Person other, bool sameId)
 {
     if (sameId)
     {
         Id.ShouldBe(other.Id);
     }
     else
     {
         Id.ShouldNotBe(other.Id);
     }
     Name.ShouldNotBe(other.Name);
     Age.ShouldNotBe(other.Age);
     Height.ShouldNotBe(other.Height);
     Dob.ShouldNotBe(other.Dob);
 }
Exemplo n.º 4
0
        private void AddOrders(int ordersToAdd)
        {
            var orderStatuses = Enum.GetValues(typeof(OrderStatus)).Cast<int>().ToArray();
            var people = new List<Person>(4);

            for (var i = 0; i < 4; i++)
            {
                var p = new Person
                {
                    Id = Guid.NewGuid(),
                    Age = 18 + i,
                    Dob = new DateTime(1980 - (18 + 1), 1, 1, 1, 1, 1, DateTimeKind.Utc),
                };
                DB.Insert(p);
                people.Add(p);
            }

            for (var i = 0; i < ordersToAdd; i++)
            {
                var order = new Order
                {
                    PoNumber = "PO" + i,
                    Status = (OrderStatus) orderStatuses.GetValue(i%orderStatuses.Length),
                    PersonId = people.Skip(i%4).Take(1).Single().Id,
                    CreatedOn = new DateTime(1990 - (i%4), 1, 1, 1, 1, 1, DateTimeKind.Utc),
                    CreatedBy = "Harry" + i
                };
                DB.Insert(order);

                for (var j = 0; j < 2; j++)
                {
                    DB.Insert(new OrderLine
                    {
                        OrderId = order.Id,
                        Quantity = (short) j,
                        SellPrice = 9.99m*j,
                        Total = 9.99m*j*j
                    });
                }
            }
        }
Exemplo n.º 5
0
        public void Delete_GivenPocoOrPrimaryKey_ShouldDeletePoco()
        {
            DB.Insert(_note);
            DB.Insert(_note2);
            DB.Insert(_person);

            DB.Delete<Person>(_person.Id).ShouldBe(1);
            DB.Delete<Note>(_note).ShouldBe(1);
            DB.Delete<Note>(new { _note2.Id }).ShouldBe(1);

            _person = DB.SingleOrDefault<Person>(_person.Id);
            _note = DB.SingleOrDefault<Note>(_note.Id);
            _note2 = DB.SingleOrDefault<Note>(_note2.Id);

            _person.ShouldBeNull();
            _note.ShouldBeNull();
            _note2.ShouldBeNull();
        }
Exemplo n.º 6
0
        public void Delete_GivenSql_ShouldDeletePoco()
        {
            DB.Insert(_note);
            DB.Insert(_person);

            DB.Delete<Note>(new Sql($"WHERE {DB.Provider.EscapeSqlIdentifier("Id")} = @0", _note.Id)).ShouldBe(1);
            DB.Delete<Person>(new Sql($"WHERE {DB.Provider.EscapeSqlIdentifier("Id")} = @0", _person.Id)).ShouldBe(1);

            _person = DB.SingleOrDefault<Person>(_person.Id);
            _note = DB.SingleOrDefault<Note>(_note.Id);

            _person.ShouldBeNull();
            _note.ShouldBeNull();
        }
Exemplo n.º 7
0
        public void Delete_GivenTableNamePrimaryKeyNamePocoAndPrimaryKeyValue_ShouldDeletePoco()
        {
            DB.Insert(_person);
            DB.Insert(_note);

            DB.Delete("People", "Id", _person, _person.Id).ShouldBe(1);
            DB.Delete("Note", "Id", _note, _note.Id).ShouldBe(1);

            _person = DB.SingleOrDefault<Person>(_person.Id);
            _note = DB.SingleOrDefault<Note>(_note.Id);

            _person.ShouldBeNull();
            _note.ShouldBeNull();
        }
Exemplo n.º 8
0
 private static void UpdateProperties(Person person)
 {
     person.Name = "Feta";
     person.Age = 19;
     person.Dob = new DateTime(1946, 1, 12, 5, 9, 4, DateTimeKind.Utc);
     person.Height = 190;
 }