コード例 #1
0
ファイル: Test.cs プロジェクト: rcaratchuk/MoqRepository
        public void CanInsertDevice()
        {
            // Create a new product, not I do not supply an id
            Device newDevice = new Device
            { Name = "Pro C#", Description = "Short description here", Price = 39.99 };

            int deviceCount = this.MockDevicesRepository.FindAll().Count;
            Assert.AreEqual(3, deviceCount); // Verify the expected Number pre-insert

            // try saving our new product
            this.MockDevicesRepository.Save(newDevice);

            // demand a recount
            deviceCount = this.MockDevicesRepository.FindAll().Count;
            Assert.AreEqual(4, deviceCount); // Verify the expected Number post-insert

            // verify that our new product has been saved
            Device testDevice = this.MockDevicesRepository.FindByName("Pro C#");
            Assert.IsNotNull(testDevice); // Test if null
            Assert.IsInstanceOf<Device>(testDevice); // Test type
            Assert.AreEqual(4, testDevice.DeviceId); // Verify it has the expected productid
        }
コード例 #2
0
 public bool Save(Device target)
 {
     // Your database code here, whether it is linq, or ADO.Net, or something else
     // That actually saves a Product to a database (insert or update), using the supplied parameter
     throw new System.NotImplementedException();
 }