public void Can_Edit_Goal() { //Prepare var goalRepository = new GoalRepository(); const int existedGoalId = 1; var oldGoal = new Goal { Id = existedGoalId, Name = "OldName", Priority = PriorityType.Low }; var expectedGoal = new Goal { Id = existedGoalId, Name = "New Name", Priority = PriorityType.High }; goalRepository.Add(oldGoal); //Pre-Validate var existedGoal = goalRepository.Goals.First(e => e.Id == existedGoalId); Assert.Equal(oldGoal.Name, existedGoal.Name); Assert.Equal(oldGoal.Priority, existedGoal.Priority); //Perform var result = goalRepository.Edit(expectedGoal); //Post-Validate Assert.Equal(expectedGoal.Id, result.Id); Assert.Equal(expectedGoal.Name, result.Name); Assert.Equal(expectedGoal.Priority, result.Priority); }
public void SaveTask() { var repository = new GoalRepository(GetTestFileFolder()); var task = new Task(); task.Id = "A9D3DD63-A0F3-4E02-A14A-8DA64CF923C3"; task.Title = "New Task"; task.Initial = 5; task.Target = 200; task.Activity.Add(new TaskActivity() { Date = DateTime.Parse("2020-03-13"), Value = 88 }); repository.SaveTask(task); var savedTask = repository.GetTask("A9D3DD63-A0F3-4E02-A14A-8DA64CF923C3"); Assert.Equal("A9D3DD63-A0F3-4E02-A14A-8DA64CF923C3", savedTask.Id); Assert.Equal("New Task", savedTask.Title); Assert.Equal(5, savedTask.Initial); Assert.Equal(200, savedTask.Target); Assert.Equal(1, savedTask.Activity.Count); Assert.Equal(DateTime.Parse("2020-03-13"), savedTask.Activity[0].Date); Assert.Equal(88, savedTask.Activity[0].Value); }
public void GetGoalList() { var repository = new GoalRepository(GetTestFileFolder()); var goalList = repository.GetGoalList($"goals.json"); Assert.Equal(6, goalList.Count); }
public void ShouldAddLoadedResourcesForMethodWhenGettingGoalById() { //Arrange int expectedId = 10; string expectedSqlStatement = "SELECT * FROM Goals;"; IEnumerable <Goal> expectedGoals = new List <Goal>() { new Goal(expectedId, "Testing Goal", "Mock Testing Goal", 100, GoalStatus.Open, false) }; mockDataAccess.Setup(da => da.ExecuteQuery <Goal>(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(expectedGoals); mockSqlStringService.Setup(ss => ss.GetSqlFromResource(It.IsAny <string>())).Returns <string>(val => { return($"{val} - {expectedSqlStatement}"); }); IGoalRepository repository = new GoalRepository(mockDataAccess.Object, mockSqlStringService.Object); //Act Goal goal = repository.GetGoal(expectedId); //Assert goal.Should().NotBeNull(); goal.Id.Should().Be(expectedId); GoalRepository goalRepo = (GoalRepository)repository; Dictionary <string, string> loadedResources = goalRepo.LoadedResources[nameof(repository.GetGoal)]; loadedResources.Should().NotBeNull(); loadedResources.Count.Should().Be(1); }
public void ShouldCreateANewGoalRepositoryWithDataAccess() { //Act IGoalRepository repository = new GoalRepository(mockDataAccess.Object, mockSqlStringService.Object); //Assert repository.Should().NotBeNull(); }
public void GetGoalDocument() { var repository = new GoalRepository(GetTestFileFolder()); var goal = repository.GetGoalDocument("8D642D0F-9CE1-4CF9-8CA6-828DFA25214E"); Assert.Equal("8D642D0F-9CE1-4CF9-8CA6-828DFA25214E", goal.Id); Assert.Equal("Highway to Hell Solo", goal.Title); }
public async Task <Goal> CreateAsync(Goal goal) { goal.Id = Guid.NewGuid(); var created = await GoalRepository.CreateAsync(goal); return(created ? goal : null); }
public List <GoalModel> SelectList() { // arrange // act var goalModel = new GoalRepository().SelectList(); // assert Assert.IsTrue(goalModel.Count > 0); return(goalModel); }
public void GetGoal() { var repository = new GoalRepository(GetTestFileFolder()); var goal = repository.GetGoal("8D642D0F-9CE1-4CF9-8CA6-828DFA25214E"); var taskReferences = goal.TaskReferences[0]; Assert.Equal("8D642D0F-9CE1-4CF9-8CA6-828DFA25214E", goal.Id); Assert.Equal("Highway to Hell Solo", goal.Title); Assert.Equal(2, goal.TaskReferences.Count); Assert.Equal("9306A3B1-6AAD-43F6-B083-C4D9FD045048", taskReferences.Id); }
public async Task <bool> DeleteAsync(Guid goalId) { if (goalId.Equals(Guid.Empty)) { return(false); } var deleted = await GoalRepository.DeleteAsync(goalId); return(deleted); }
public GoalViewModel(Goal goal) { goalRep = new GoalRepository(); TheTitle = goal.Title; TheCurrentValue = Convert.ToString(goal.CurrentValue); TheGoalValue = Convert.ToString(goal.GoalValue); TheEndDate = goal.EndDate; TheIsFinished = goal.IsFinished; progress = goal.Progress; SaveGoalCommand = new Command(async() => { goal.Title = TheTitle; goal.CurrentValue = Convert.ToDouble(TheCurrentValue); goal.GoalValue = Convert.ToDouble(TheGoalValue); goal.StartDate = DateTime.Now; goal.EndDate = TheEndDate; goal.Progress = goal.CurrentValue / goal.GoalValue; await goalRep.SaveGoalAsync(goal); TheTitle = string.Empty; TheCurrentValue = string.Empty; TheGoalValue = string.Empty; TheIsFinished = false; TheEndDate = DateTime.MinValue; progress = 0; }); UpdateGoalCommand = new Command(async() => { goal.Title = TheTitle; goal.CurrentValue = Convert.ToDouble(TheCurrentValue) + Convert.ToDouble(TheAddValue); goal.GoalValue = Convert.ToDouble(TheGoalValue); goal.Progress = goal.CurrentValue / goal.GoalValue; if (goal.Progress >= 1) { goal.IsFinished = true; goal.EndDate = DateTime.Now; } await goalRep.SaveGoalAsync(goal); TheTitle = string.Empty; TheCurrentValue = string.Empty; TheGoalValue = string.Empty; TheIsFinished = false; TheEndDate = DateTime.MinValue; progress = 0; }); RemoveGoal = new Command(async() => { await goalRep.DeleteGoalAsync(goal); }); }
public GoalModel Select(int id) { // arrange int _id = id; // act var goalModel = new GoalRepository().Select(_id); // assert Assert.IsTrue(goalModel.Id > 0); return(goalModel); }
public static void QueryGoals() { MatchRepository matchRepo = new MatchRepository(); var matches = matchRepo.List.ToList(); GoalRepository goalRepository = new GoalRepository(); //Premier League //int matchesCount = matches.Where(x => x.League == "Spain Primera Division").Count(); //foreach (Match match in matches.Where(x => x.League == "Spain Primera Division")) //{ // int id = int.Parse(match.ExternalId); // var goals = goalRepository.List.Where(x => x.MatchId == id).OrderBy(y => y.Minute); //} }
public void GetTask() { var repository = new GoalRepository(GetTestFileFolder()); var task = repository.GetTask("290D51D0-6918-41CE-9734-8EA7870DB218"); var activity = task.Activity[0]; Assert.Equal("290D51D0-6918-41CE-9734-8EA7870DB218", task.Id); Assert.Equal("Highway to Hell - Lick 2", task.Title); Assert.Equal(0, task.Initial); Assert.Equal(100, task.Target); Assert.Equal(3, task.Activity.Count); Assert.Equal(DateTime.Parse("2019-05-04"), activity.Date); }
public void SaveGoalList() { var repository = new GoalRepository(GetTestFileFolder()); var goalList = repository.GetGoalList($"goals.json"); goalList.Add(new GoalListItem { Id = "8D642D0F-9CE1-4CF9-8CA6-828DFA25214E", PercentComplete = 99, Title = "Added Goal" }); repository.SaveGoalList(goalList, $"saved_goals.json"); var goalListNew = repository.GetGoalList($"saved_goals.json"); }
public void LoadGoalTasksFromTaskReferences() { var repository = new GoalRepository(GetTestFileFolder()); var goal = repository.GetGoal("8D642D0F-9CE1-4CF9-8CA6-828DFA25214E"); var tasks = repository.GetTasks(goal.TaskReferences); Assert.Equal(2, tasks.Count); Assert.Equal("290D51D0-6918-41CE-9734-8EA7870DB218", tasks[1].Id); Assert.Equal("Highway to Hell - Lick 2", tasks[1].Title); Assert.Equal(0, tasks[1].Initial); Assert.Equal(100, tasks[1].Target); Assert.Equal(3, tasks[1].Activity.Count); Assert.Equal(DateTime.Parse("2019-05-04"), tasks[1].Activity[0].Date); Assert.Equal(33.33, tasks[1].Activity[0].Value); }
public UnitOfWork(JobDBContext _context) { context = _context; Awards = new AwardRepository(context); FamilyMembers = new FamilyMemberRepository(context); FamilyMemberRoles = new FamilyMemberRoleRepository(context); Families = new FamilyRepository(context); Goals = new GoalRepository(context); JobCategories = new JobCategoryRepository(context); Jobs = new JobRepository(context); JobTemplates = new JobTemplateRepository(context); MemberJobs = new MemberJobRepository(context); MemberGoals = new MemberGoalRepository(context); }
public int Insert(GoalModel obj) { // arrange var goalModel = new GoalModel() { Name = "Goal Name" }; // act var newId = new GoalRepository().Insert(goalModel); // assert Assert.IsTrue(newId > 0); return(newId); }
public void ShouldConvertFromAnonymousTypeToDictionaryOfParameters() { //Arrange DateTime expectedDate = DateTime.Now; var anonymous = new { Value1 = "Testing", Value2 = 1, Value3 = expectedDate, Value4 = 'c' }; string[] expectedKeys = new string[] { "Value1", "Value2", "Value3", "Value4" }; object[] expectedValues = { "Testing", 1, expectedDate, 'c' }; GoalRepository repository = new GoalRepository(mockDataAccess.Object, mockSqlStringService.Object); //Act Dictionary <string, object> parameterDictionary = repository.ConvertToParameters(anonymous); //Assert parameterDictionary.Count.Should().Be(4); parameterDictionary.Keys.Should().ContainInOrder(expectedKeys); parameterDictionary.Values.Should().ContainInOrder(expectedValues); }
public void Can_Create_Goal() { // Prepare var goalRepository = new GoalRepository(); var goal = new Goal(); const string expectedName = "Тестовая задача"; goal.Name = expectedName; // Pre-Validate // Perform var result = goalRepository.Add(goal); // Post-Validate Assert.NotNull(result); Assert.Equal(result, goalRepository.Goals.First()); Assert.Equal(expectedName, result.Name); }
public void Can_Get() { //Prepare var goalRepository = new GoalRepository(); const int existedGoalId = 1; var goal = new Goal { Id = existedGoalId }; goalRepository.Add(goal); //Pre-Validate var existedGoal = goalRepository.Goals.First(e => e.Id == existedGoalId); Assert.Equal(existedGoalId, existedGoal.Id); //Perform var result = goalRepository.Get(goal.Id); //Post-Validate Assert.Equal(result, goal); }
public void GoalRepository() { Mock <IDbSetFactory> factory = new Mock <IDbSetFactory>(); Mock <DbSet <Goal> > dbSet = new Mock <DbSet <Goal> >(); factory.Setup(m => m.CreateDbSet <Goal>()).Returns(dbSet.Object); GoalRepository repo = new GoalRepository(factory.Object); var Goal = new Goal(); var sequence = new MockSequence(); dbSet.InSequence(sequence).Setup(e => e.Add(Goal)); dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id)); dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id)); dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id)); repo.Create(Goal); repo.Get(Goal.Id); repo.Update(Goal); repo.Delete(Goal.Id); }
public GoalViewModel() { goalRep = new GoalRepository(); SaveGoalCommand = new Command(async() => { var goal = new Goal(); goal.Title = TheTitle; goal.CurrentValue = Convert.ToDouble(TheCurrentValue); goal.GoalValue = Convert.ToDouble(TheGoalValue); goal.StartDate = DateTime.Now; goal.EndDate = TheEndDate; goal.Progress = goal.CurrentValue / goal.GoalValue; if (goal.Progress >= 1) { goal.IsFinished = true; } else { goal.IsFinished = false; } await goalRep.SaveGoalAsync(goal); }); }
public void Can_Delete() { //Prepare var goalRepository = new GoalRepository(); const int existedGoalId = 1; var goal = new Goal { Id = existedGoalId }; goalRepository.Add(goal); //Pre-Validate var existedGoal = goalRepository.Goals.FirstOrDefault(e => e.Id == existedGoalId); Assert.NotNull(existedGoal); Assert.Equal(existedGoalId, existedGoal.Id); //Perform goalRepository.Delete(goal); //Post-Validate Assert.DoesNotContain(goalRepository.Goals, e => e.Id == existedGoalId); }
public void CreateUpdateDeleteFetch() { // file system var path = "/shop/randomsilo/modern-web/backends/GoalTracker"; var project = "GoalTracker"; var outputPath = $"{path}/{project}.Infrastructure.Test/TestOutput/"; var databaseFile = GetDatabase(outputPath, MethodBase.GetCurrentMethod()); // logger ILogger logger = GetLogger($"{outputPath}/{MethodBase.GetCurrentMethod().ReflectedType.Name}_{MethodBase.GetCurrentMethod().Name}.log"); // database setup // - context IDatabaseContext databaseContext = new DatabaseContext( $"Data Source={databaseFile}" , "TestDb" , "TestSchema" , $"{path}/sql/sqlite/ALL.sql" ); Assert.NotNull(databaseContext); // - manager IManageDatabase databaseManager = new DatabaseManager(databaseContext); Assert.NotNull(databaseManager); // - create tables databaseManager.CreateDatabase(); // - repository var goalRepository = new GoalRepository(databaseManager, new GoalRepositorySql(), logger); Assert.NotNull(goalRepository); // faker BrashActionResult <Goal> result = null; var goalFaker = new GoalFaker(databaseManager, logger); Assert.NotNull(goalFaker); // create var goalCreateModel = goalFaker.GetOne(); result = goalRepository.Create(goalCreateModel); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); Assert.True(result.Model.GoalId > 0); // use model with id goalCreateModel = result.Model; // update var goalUpdateModel = goalFaker.GetOne(); goalUpdateModel.GoalId = goalCreateModel.GoalId; result = goalRepository.Update(goalUpdateModel); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); // delete result = goalRepository.Delete(goalCreateModel); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); // fetch // - make fakes var fakes = goalFaker.GetMany(10); // - add fakes to database List <int?> ids = new List <int?>(); foreach (var f in fakes) { result = goalRepository.Create(f); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); Assert.True(result.Model.GoalId >= 0); ids.Add(result.Model.GoalId); } // - get fakes from database foreach (var id in ids) { var model = new Goal() { GoalId = id }; result = goalRepository.Fetch(model); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); Assert.True(result.Model.GoalId >= 0); } }
public bool Delete(int id) { return(GoalRepository.DeleteGoal(id)); }
public bool Put(int id) { return(GoalRepository.UpdateGoal(id)); }
public bool Post([FromBody] GoalModel goal) { return(GoalRepository.CreateNewGoal(goal)); }
public GoalModel Get(int id) { return(GoalRepository.GetGoal(id)); }
public IEnumerable <GoalModel> Get() { return(GoalRepository.GetGoals()); }
public void GoalRepository() { Mock<IDbSetFactory> factory = new Mock<IDbSetFactory>(); Mock<DbSet<Goal>> dbSet = new Mock<DbSet<Goal>>(); factory.Setup(m => m.CreateDbSet<Goal>()).Returns(dbSet.Object); GoalRepository repo = new GoalRepository(factory.Object); var Goal = new Goal(); var sequence = new MockSequence(); dbSet.InSequence(sequence).Setup(e => e.Add(Goal)); dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id)); dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id)); dbSet.InSequence(sequence).Setup(e => e.Find(Goal.Id)); repo.Create(Goal); repo.Get(Goal.Id); repo.Update(Goal); repo.Delete(Goal.Id); }