Пример #1
0
        public void Delete_WithInvalidWocketId_RemovesRecord()
        {
            // Arrange
            var fakeWocket1 = new Wocket { Id = 1 };
            var fakeWocket2 = new Wocket { Id = 2 };
            var fakeWocket3 = new Wocket { Id = 3 };
            var fakeStore = new List<Wocket> { fakeWocket1, fakeWocket2, fakeWocket3 };
            var mockObjectStore = new Mock<IObjectStore<Wocket>>();
            mockObjectStore.Setup(x => x.GetEnumerator()).Returns(fakeStore.GetEnumerator());

            var repository = new WocketRepository(mockObjectStore.Object);

            // Act
            // Assert
            Assert.Throws<ArgumentException>(() => repository.Delete(99));
        }
Пример #2
0
        public void GetAll_WithExistingWockets_ReturnsFullArray()
        {
            // Arrange
            var fakeWocket1 = new Wocket { Id = 1 };
            var fakeWocket2 = new Wocket { Id = 2 };
            var fakeWocket3 = new Wocket { Id = 3 };
            var fakeStore = new List<Wocket> { fakeWocket1, fakeWocket2, fakeWocket3 };
            var mockObjectStore = new Mock<IObjectStore<Wocket>>();
            mockObjectStore.Setup(x => x.GetEnumerator()).Returns(fakeStore.GetEnumerator());
            var repository = new WocketRepository(mockObjectStore.Object);

            // Act
            var result = repository.GetAll();

            // Assert
            Assert.Contains(fakeWocket1, result);
            Assert.Contains(fakeWocket2, result);
            Assert.Contains(fakeWocket3, result);
        }
Пример #3
0
        public void Delete_WithExistingWocketId_RemovesRecord()
        {
            // Arrange
            var fakeWocket1 = new Wocket { Id = 1 };
            var fakeWocket2 = new Wocket { Id = 2 };
            var fakeWocket3 = new Wocket { Id = 3 };
            var fakeStore = new List<Wocket> { fakeWocket1, fakeWocket2, fakeWocket3 };
            var mockObjectStore = new Mock<IObjectStore<Wocket>>();
            mockObjectStore.Setup(x => x.GetEnumerator()).Returns(fakeStore.GetEnumerator());
            mockObjectStore.Setup(x => x.Delete(fakeWocket1)).Verifiable();

            var repository = new WocketRepository(mockObjectStore.Object);

            // Act
            repository.Delete(fakeWocket1.Id);

            // Assert
            mockObjectStore.VerifyAll();
        }
Пример #4
0
        public void Save(Wocket wocket)
        {
            if (wocket.Id == 0)
            {
                // Getting the Id from the objectStore is optional.
                // NextId provides a static sequential integer Id.
                wocket.Id = _objectStore.NextId;
                _objectStore.Insert(wocket);
                return;
            }

            var oldWocket = GetById(wocket.Id);
            _objectStore.Replace(oldWocket, wocket);
        }
Пример #5
0
        public void Save_WithNewValidWocket_InsertsRecord()
        {
            // Arrange
            var fakeWocket1 = new Wocket { Id = 0 };
            var mockObjectStore = new Mock<IObjectStore<Wocket>>();
            mockObjectStore.Setup(x => x.Insert(fakeWocket1)).Verifiable();
            var repository = new WocketRepository(mockObjectStore.Object);

            // Act
            repository.Save(fakeWocket1);

            // Assert
            mockObjectStore.VerifyAll();
        }
Пример #6
0
        public void Save_WithExistingValidWocket_UpdatesRecord()
        {
            // Arrange
            var oldWocket = new Wocket { Id = 1, Name = "Some wocket" };
            var newWocket = new Wocket { Id = 1, Name = "Some other wocket" };
            var fakeStore = new List<Wocket> { oldWocket };

            var mockObjectStore = new Mock<IObjectStore<Wocket>>();
            mockObjectStore.Setup(x => x.GetEnumerator())
                .Returns(fakeStore.GetEnumerator());
            mockObjectStore.Setup(x => x.Replace(oldWocket, newWocket))
                .Verifiable("wocket was not replaced");

            var repository = new WocketRepository(mockObjectStore.Object);

            // Act
            repository.Save(newWocket);

            // Assert
            mockObjectStore.VerifyAll();
        }
Пример #7
0
        public void GetById_WithValidId_ReturnsObject()
        {
            // Arrange
            var fakeWocket = new Wocket { Id = 2 };
            var fakeStore = new List<Wocket> { fakeWocket };
            var mockObjectStore = new Mock<IObjectStore<Wocket>>();
            mockObjectStore.Setup(x => x.GetEnumerator()).Returns(fakeStore.GetEnumerator());
            var repository = new WocketRepository(mockObjectStore.Object);

            // Act
            var result = repository.GetById(2);

            // Assert
            Assert.AreSame(fakeWocket, result);
        }
Пример #8
0
 public ViewResult Create()
 {
     var wocket = new Wocket();
     return View("Edit", wocket);
 }
Пример #9
0
 public ActionResult Save(Wocket wocket)
 {
     try
     {
         _wocketRepository.Save(wocket);
         return RedirectToAction("Index");
     }
     catch (Exception exception)
     {
         return ShowError(exception);
     }
 }