public async Task TestCreateOrderTransaction()
        {
            var placedDate = DateTime.Now;
            var supplier   = _context.Suppliers.First();
            var order      = new Order()
            {
                PartTypeId = supplier.PartTypeId,
                SupplierId = supplier.Id,
                PartCount  = 10,
                PlacedDate = placedDate
            };

            await Assert.ThrowsAsync <NullReferenceException>(async() => await _context.CreateOrder(order));

            using (var command = new SqliteCommand(
                       @"SELECT Count(*) FROM [Order] WHERE
                SupplierId=@supplierId AND
                PartTypeId=@partTypeId AND
                PlacedDate=@placedDate AND
                PartCount=10 AND
                FulfilledDate IS NULL", _fixture.Connection
                       ))
            {
                _context.AddParameter(command, "@supplierId", order.SupplierId);
                _context.AddParameter(command, "@partTypeId", order.PartTypeId);
                _context.AddParameter(command, "@placedDate", order.PlacedDate);

                Assert.Equal(0, (long)await command.ExecuteScalarAsync());
            }
        }
Beispiel #2
0
        public void TestCreateOrderTransaction()
        {
            var placedDate = DateTime.Now;
            var supplier   = context.Suppliers.First();
            var order      = new Order()
            {
                PartTypeId = supplier.PartTypeId,
                SupplierId = supplier.Id,
                PartCount  = 10,
                PlacedDate = placedDate
            };

            Assert.Throws <NullReferenceException>(() =>
                                                   context.CreateOrder(order));

            var command = new SqliteCommand(
                @"
                SELECT Count(*)
                FROM [Order]
                WHERE SupplierId = @supplierId
                  AND PartTypeId = @partTypeId
                  AND PlacedDate = @placedDate
                  AND PartCount = 10
                  AND FulfilledDate IS NULL;
                ", fixture.Connection);

            AddParameter(command, "@supplierId", supplier.Id);
            AddParameter(command, "@partTypeId", supplier.PartTypeId);
            AddParameter(command, "@placedDate", placedDate);
            Assert.Equal(0, (long)command.ExecuteScalar());
        }
        public void TestCreateOrder()
        {
            var placedDate = DateTime.Now;
            var supplier   = context.Suppliers.First();
            var order      = new Order()
            {
                PartTypeId = supplier.PartTypeId,
                Part       = context.Parts.Single(p => p.Id == supplier.PartTypeId),
                SupplierId = supplier.Id,
                Supplier   = supplier,
                PartCount  = 10,
                PlacedDate = placedDate
            };

            context.CreateOrder(order);

            var command = new SqliteCommand(
                @"SELECT Id FROM [Order] WHERE 
          SupplierId=@supplierId AND 
          PartTypeId=@partTypeId AND
          PlacedDate=@placedDate AND
          PartCount=10 AND
          FulfilledDate IS NULL",
                fixture.Connection);

            AddParameter(command, "@supplierId", supplier.Id);
            AddParameter(command, "@partTypeId", supplier.PartTypeId);
            AddParameter(command, "@placedDate", placedDate);
            var scalar = command.ExecuteScalar();

            Assert.NotNull(scalar);
            Assert.IsType <long>(scalar);
            long orderId = (long)scalar;

            Assert.Equal(order.Id, orderId);

            command = new SqliteCommand(
                $@"SELECT Count(*) FROM SendEmailCommand 
          WHERE [To]=@email AND 
          Subject LIKE @subject",
                fixture.Connection);
            AddParameter(command, "@email", supplier.Email);
            AddParameter(command, "@subject", $"Order #{order.Id}%");
            Assert.Equal(1, (long)command.ExecuteScalar());
        }