Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 4
0
        public void GetById_WithInvalidId_Throws()
        {
            // Arrange
            var fakeStore = new List<Wocket>();
            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.GetById(2));
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }