public void MakeLicensePlatePrimaryWithAllTrue_ShouldSetPrimaryTrue_RestFalse() { var repoMock = NSubstitute.Substitute.For <IGenericRepository <LicensePlate> >(); repoMock.AsQueryable().ReturnsForAnyArgs(new List <LicensePlate>() { new LicensePlate() { Description = "Beskrivelse 1", IsPrimary = true, Id = 1, PersonId = 1, }, new LicensePlate() { Description = "Beskrivelse 2", IsPrimary = true, Id = 2, PersonId = 1, }, new LicensePlate() { Description = "Beskrivelse 2", IsPrimary = true, Id = 3, PersonId = 1, }, }.AsQueryable()); uut = new LicensePlateService(repoMock); uut.MakeLicensePlatePrimary(2); Assert.IsFalse(repoMock.AsQueryable().ElementAt(0).IsPrimary); Assert.IsFalse(repoMock.AsQueryable().ElementAt(2).IsPrimary); Assert.IsTrue(repoMock.AsQueryable().ElementAt(1).IsPrimary); }
public void MakeLicensePlatePrimary_ShouldNotEdit_PlatesBelongingToDifferentUser() { var repoMock = NSubstitute.Substitute.For <IGenericRepository <LicensePlate> >(); repoMock.AsQueryable().ReturnsForAnyArgs(new List <LicensePlate>() { new LicensePlate() { Description = "Beskrivelse 1", IsPrimary = false, Id = 1, PersonId = 1, }, new LicensePlate() { Description = "Beskrivelse 2", IsPrimary = false, Id = 2, PersonId = 1, }, new LicensePlate() { Description = "Beskrivelse 2", IsPrimary = false, Id = 3, PersonId = 1, }, new LicensePlate() { Description = "Beskrivelse 2", IsPrimary = true, Id = 4, PersonId = 2, }, new LicensePlate() { Description = "Beskrivelse 2", IsPrimary = true, Id = 5, PersonId = 2, }, }.AsQueryable()); uut = new LicensePlateService(repoMock); uut.MakeLicensePlatePrimary(2); Assert.IsTrue(repoMock.AsQueryable().ElementAt(1).IsPrimary); Assert.True(repoMock.AsQueryable().ElementAt(3).IsPrimary); Assert.IsTrue(repoMock.AsQueryable().ElementAt(4).IsPrimary); }
public void NoExistingPlates_PostedPlate_ShouldBeMadePrimary() { _repoMock = NSubstitute.Substitute.For <IGenericRepository <LicensePlate> >(); _repoMock.AsQueryable().ReturnsForAnyArgs(new List <LicensePlate>() { }.AsQueryable()); uut = new LicensePlateService(_repoMock); var plate = new LicensePlate() { PersonId = 1 }; uut.HandlePost(plate); Assert.AreEqual(true, plate.IsPrimary); }
public void MakeLicensePlatePrimary_ShouldReturnFalse_WhenPlateDoesntExists() { var repoMock = NSubstitute.Substitute.For <IGenericRepository <LicensePlate> >(); repoMock.AsQueryable().ReturnsForAnyArgs(new List <LicensePlate>() { new LicensePlate() { Description = "Beskrivelse 2", IsPrimary = true, Id = 5, PersonId = 2, }, }.AsQueryable()); uut = new LicensePlateService(repoMock); Assert.IsFalse(uut.MakeLicensePlatePrimary(2)); }
public void TwoExistingPlates_DeleteNonPrimary_RemainingShouldStillBePrimary() { _repoMock = NSubstitute.Substitute.For <IGenericRepository <LicensePlate> >(); _repoMock.AsQueryable().ReturnsForAnyArgs(new List <LicensePlate>() { new LicensePlate() { Id = 1, IsPrimary = true, PersonId = 1 }, new LicensePlate() { Id = 2, IsPrimary = false, PersonId = 1 } }.AsQueryable()); uut = new LicensePlateService(_repoMock); uut.HandleDelete(_repoMock.AsQueryable().First(x => x.Id == 2)); Assert.AreEqual(true, _repoMock.AsQueryable().First(x => x.Id == 1).IsPrimary); }
public LicensePlatesController(IServiceProvider provider) : base(provider) { _plateService = provider.GetService <ILicensePlateService>(); }
public LicensePlatesController(IGenericRepository <LicensePlate> repo, ILicensePlateService plateService, IGenericRepository <Person> personRepo) : base(repo, personRepo) { _plateService = plateService; }