public void AddDivisions() { // Arrange var repository = new DivisionRepository(); var dbContext = A.Fake <ProFootballEntities>(); var divisions = new List <Division>(); for (int i = 1; i <= 3; i++) { var division = new Division { Name = "Division " + i }; divisions.Add(division); } A.CallTo(() => dbContext.Divisions.AddRange(A <IEnumerable <Division> > .Ignored)).Returns(divisions); // Act var result = repository.AddEntities(dbContext, divisions); // Assert A.CallTo(() => dbContext.Divisions.AddRange(divisions)).MustHaveHappenedOnceExactly(); Assert.AreSame(divisions, result); }
public void AddDivisions_HappyPath() { // Arrange var dbContext = A.Fake <ProFootballEntities>(); var repository = new DivisionRepository(dbContext); var divisions = new List <Division>(); A.CallTo(() => dbContext.Divisions.AddRange(A <IEnumerable <Division> > .Ignored)).Returns(divisions); // Act var result = repository.AddEntities(divisions); // Assert A.CallTo(() => dbContext.Divisions.AddRange(divisions)).MustHaveHappenedOnceExactly(); Assert.AreSame(divisions, result); }
public void AddDivisions_ExceptionCaught_LogsAndRethrowsException() { // Arrange var dbContext = A.Fake <ProFootballEntities>(); var repository = new DivisionRepository(dbContext); var divisions = new List <Division>(); A.CallTo(() => dbContext.Divisions.AddRange(A <IEnumerable <Division> > .Ignored)).Throws <Exception>(); // Act IEnumerable <Division> result = null; Assert.Throws <Exception>(() => result = repository.AddEntities(divisions)); // Assert Assert.IsNull(result); }