public void Not_Add_IfTown_Exists() { var contextOptions = new DbContextOptionsBuilder <LibrarySystemContext>() .UseInMemoryDatabase(databaseName: "Not_Add_IfTown_Exists") .Options; var validationMock = new Mock <CommonValidations>(); string town1 = "test 1"; string town2 = "test 1"; // Act using (var actContext = new LibrarySystemContext(contextOptions)) { var unit = new UnitOfWork(actContext); var repo = unit.GetRepo <Town>(); var service = new TownService(unit, validationMock.Object); service.AddTown(town1); service.AddTown(town2); } // Assert using (var assertContext = new LibrarySystemContext(contextOptions)) { var unit = new UnitOfWork(assertContext); var repo = unit.GetRepo <Town>(); var service = new TownService(unit, validationMock.Object); int count = assertContext.Towns.Count(); Assert.AreEqual(1, count); Assert.AreEqual(town1, assertContext.Towns.First().TownName); } }
public void Throw_Exeption_IfUser_IsDeleted() { //Arrange var contextOptions = new DbContextOptionsBuilder <LibrarySystemContext>() .UseInMemoryDatabase(databaseName: "Change_User_Address") .Options; string firstName = "Ivan1", middleName = "Ivanov1", lastName = "Ivanov1", phoneNumber = "1234567899"; DateTime addOnDate = DateTime.Now; bool isDeleted = false; var validationMock = new Mock <CommonValidations>(); using (var actContext = new LibrarySystemContext(contextOptions)) { var unit = new UnitOfWork(actContext); var townService = new TownService(unit, validationMock.Object); var addressService = new AddressService(unit, validationMock.Object); var userService = new UsersServices(unit, validationMock.Object); var town = townService.AddTown("test"); var address = addressService.AddAddress("test address", town); //Act & Assert userService.AddUser(firstName, middleName, lastName, phoneNumber, addOnDate, isDeleted, address); userService.RemoveUser(firstName, middleName, lastName); userService.UpdateUserAddress(firstName, middleName, lastName, 3); } }
public static void ImportTown(TownDTO townDto) { string townName = townDto.Name; InputDataValidator.ValidateStringMaxLength(townName, Constants.MaxTownNameLength); TownValidator.ValidateTownDoesNotExist(townName); TownService.AddTown(townName); Console.WriteLine(string.Format(Constants.ImportSuccessMessages.TownAddedSuccess, townName)); }
// AddTown <townName> <countryName> public override string Execute(string[] data) { string townName = data[0]; string country = data[1]; if (this.townService.IsTownExisting(townName)) { throw new ArgumentException($"Town {townName} already exists!"); } townService.AddTown(townName, country); return(townName + " was added to database!"); }
public void Get_User_FromDatabase_IfUser_Exists() { //Arrange var contextOptions = new DbContextOptionsBuilder <LibrarySystemContext>() .UseInMemoryDatabase(databaseName: "Get_User_FromDatabase") .Options; string firstName = "Ivan", middleName = "Ivanov", lastName = "Ivanov", phoneNumber = "1234567899"; DateTime addOnDate = DateTime.Now; bool isDeleted = false; string fullName = firstName + " " + middleName + " " + lastName; var validationMock = new Mock <CommonValidations>(); using (var actContext = new LibrarySystemContext(contextOptions)) { var unit = new UnitOfWork(actContext); var townService = new TownService(unit, validationMock.Object); var addressService = new AddressService(unit, validationMock.Object); var userService = new UsersServices(unit, validationMock.Object); var town = townService.AddTown("test"); var address = addressService.AddAddress("test address", town); userService.AddUser(firstName, middleName, lastName, phoneNumber, addOnDate, isDeleted, address); } using (var assertContext = new LibrarySystemContext(contextOptions)) { var unit = new UnitOfWork(assertContext); var userService = new UsersServices(unit, validationMock.Object); //Act var getUser = userService.GetUser(firstName, middleName, lastName); //Assert Assert.AreEqual(fullName, getUser.FullName); } }
// AddTown <townName> <countryName> public string Execute(string[] data) { string townName = data[0]; string country = data[1]; // 2. Extend Photo Share System if (!AuthenticationService.IsAuthenticated()) { throw new InvalidOperationException("Invalid credentials! You should log in first."); } if (this.townService.IsExistingTown(townName)) { throw new ArgumentException($"Town {townName} was already added!"); } townService.AddTown(townName, country); return($"Town {townName} was added successfully!"); }
public void Add_User_ToDatabase() { //Arrange var contextOptions = new DbContextOptionsBuilder <LibrarySystemContext>() .UseInMemoryDatabase(databaseName: "Add_User_ToDatabase") .Options; string firstName = "Ivan", middleName = "Ivanov", lastName = "Ivanov", phoneNumber = "1234567899"; DateTime addOnDate = DateTime.Now; bool isDeleted = false; var validationMock = new Mock <CommonValidations>(); using (var actContext = new LibrarySystemContext(contextOptions)) { var unit = new UnitOfWork(actContext); var townService = new TownService(unit, validationMock.Object); var addressService = new AddressService(unit, validationMock.Object); var userService = new UsersServices(unit, validationMock.Object); var town = townService.AddTown("test"); var address = addressService.AddAddress("test address", town); //Act userService.AddUser(firstName, middleName, lastName, phoneNumber, addOnDate, isDeleted, address); } // Assert using (var assertContext = new LibrarySystemContext(contextOptions)) { int count = assertContext.Users.Count(); Assert.AreEqual(1, count); Assert.AreEqual(firstName, assertContext.Users.First().FirstName); } }
public void SeedTableTowns() { townService.AddTown("Bulgaria", "Plovdiv"); townService.AddTown("Bulgaria", "Burgas"); townService.AddTown("Bulgaria", "Varna"); townService.AddTown("Bulgaria", "Nessebar"); townService.AddTown("Bulgaria", "Bansko"); townService.AddTown("Bulgaria", "Borovets"); townService.AddTown("Bulgaria", "Velingrad"); townService.AddTown("Bulgaria", "Sunny Beach"); townService.AddTown("Germany", "Berlin"); townService.AddTown("Germany", "Munich"); townService.AddTown("Germany", "Hanover"); townService.AddTown("Greece", "Kavala"); townService.AddTown("Greece", "Athens"); townService.AddTown("Greece", "Halkidiki"); townService.AddTown("Greece", "Thessaloniki"); townService.AddTown("Serbia", "Belgrade"); townService.AddTown("Serbia", "Dimitrovgrad"); townService.AddTown("France", "Paris"); townService.AddTown("France", "Lion"); townService.AddTown("Russia", "Moscow"); townService.AddTown("Russia", "St. Petersburg"); townService.AddTown("Turkey", "Edirne"); townService.AddTown("Turkey", "Istanbul"); townService.AddTown("Austria", "Vienna"); townService.AddTown("Austria", "Salzburg"); townService.AddTown("Hungary", "Budapest"); townService.AddTown("Norway", "Oslo"); }