public void Initialize() { AutoMapperConfigurator.Configure(); _repositoryMock = new Mock<IRepository<StoredProtocol>>(); _storedProtocol = new StoredProtocol {}; // TODO insert data _protocol = new Protocol {}; // TODO insert data }
public async Task Create_SaveChanged_IsCalled() { // Arrange var protocol = new StoredProtocol(); // Act var id = await _repository.Create(protocol); // Assert _context.Verify(c => c.SaveChangesAsync(), Times.Once); }
public async Task Update_InvalidUser_ReturnsFalse() { //Arrange var newProtocol = new StoredProtocol(); // Act var isUpdated = await _repository.UpdateIfExists(newProtocol); // Assert Assert.IsFalse(isUpdated); }
public async Task Update_ValidProtocol_ReturnsTrue() { // Arrange var firstProtocolUpdated = new StoredProtocol { Id = 1 }; // Act var isUpdated = await _repository.UpdateIfExists(firstProtocolUpdated); // Assert Assert.IsTrue(isUpdated); }
public async Task Update_SaveChangesAsync_IsCalled() { // Arrange var firstProtocolUpdated = new StoredProtocol { Id = 1 }; // Act await _repository.UpdateIfExists(firstProtocolUpdated); // Assert _context.Verify(c => c.SaveChangesAsync(), Times.Once); }
public async Task Update_Attach_IsCalled() { // Arrange var firstStudyUpdated = new StoredProtocol { Id = 1 }; // Act await _repository.UpdateIfExists(firstStudyUpdated); // Assert _context.Verify(c => c.Attach(firstStudyUpdated), Times.Once); }
public async Task Update_FindAsync_IsCalled() { // Arrange var firstProtocolUpdated = new StoredProtocol { Id = 1 }; _mockSet.Setup(t => t.FindAsync(1)) .Returns(Task.FromResult(It.IsAny<StoredProtocol>())); // Act await _repository.UpdateIfExists(firstProtocolUpdated); // Assert _mockSet.Verify(m => m.FindAsync(1), Times.Once); }
public async Task Create_Add_IsCalled() { // Arrange var validProtocol = new StoredProtocol {Id = 0}; // Act await _repository.Create(validProtocol); // Assert _context.Verify(c => c.Add(validProtocol), Times.Once); }
public async Task Update_SetAttachProtocol_IsCalled() { // Arrange var protocol = new StoredProtocol {Id = 1 }; // Act await _repository.UpdateIfExists(protocol); // Assert _context.Verify(c => c.Attach(protocol), Times.Once); }
public async Task Create_ReturnsId_NewId() { // Arrange var mockSet = new Mock<DbSet<StoredProtocol>>(); var mockContext = new Mock<IAutoSysContext>(); mockContext.Setup(m => m.Protocols).Returns(mockSet.Object); var protocol = new StoredProtocol(); // Act var service = new ProtocolRepository(mockContext.Object); var id = await service.Create(protocol); // Assert Assert.AreEqual(protocol.Id, id); // True for EF but not for interface }
public void Create_SaveChanges_IsCalled() { // Arrange var protocol = new StoredProtocol(); // Act var id = _repository.Create(protocol); // Assert _context.Verify(r => r.SaveChangesAsync(), Times.Once); }
public void GetAllProtocols_Valid_ReturnsCorrectProtocols_Test() { // TODO add property values //Arrange var protocol1 = new StoredProtocol {}; var protocol2 = new StoredProtocol {}; var protocol3 = new StoredProtocol {}; var protocolList = new List<StoredProtocol> { protocol1, protocol2, protocol3 }.AsQueryable(); _repositoryMock.Setup(r => r.Read()).Returns(protocolList); var adapter = new ProtocolAdapter(_repositoryMock.Object); //Act var result = adapter.Read(); var actualProtocols = result.ToList(); //Assert var counter = 0; foreach (var actualProtocol in protocolList.AsEnumerable()) { var returnedProtocol = actualProtocols[counter]; // Todo add property asserts Assert.IsTrue(returnedProtocol.StudyName == actualProtocol.StudyName); counter++; } }
public void GetAllProtocols_Valid_ReturnsCorrectNumberOfProtocols_Test() { //Arrange var protocol1 = new StoredProtocol { }; var protocol2 = new StoredProtocol { }; var protocol3 = new StoredProtocol { }; var protocolList = new List<StoredProtocol> { protocol1, protocol2, protocol3 }.AsQueryable(); _repositoryMock.Setup(r => r.Read()).Returns(protocolList); var adapter = new ProtocolAdapter(_repositoryMock.Object); const int expectedCount = 3; //Act var result = adapter.Read(); var actualCount = result.ToList().Count; //Assert Assert.IsTrue(expectedCount == actualCount); }