Ejemplo n.º 1
0
        public Boolean AddToDatesList(DateTime enterDateTime)
        {
            IsLoading  = true;
            Dictionary = DataManager.Instance.GetDailyEntriesData();

            if (Dictionary.ContainsKey(enterDateTime))
            {
                if (AddAlreadyAddedDate != null)
                {
                    AddAlreadyAddedDate(this, enterDateTime);
                }

                IsLoading = false;
                return(false);
            }

            var dailyEntry = new DailyEntry(enterDateTime);

            Dictionary.Add(enterDateTime, dailyEntry);
            UpdateDatesList(Dictionary);

            if (!DataManager.Instance.SaveDailyEntriesData(Dictionary))
            {
                if (ErrorOccurred != null)
                {
                    ErrorOccurred(this, null);
                }

                IsLoading = false;
                return(false);
            }

            IsLoading = false;
            return(true);
        }
Ejemplo n.º 2
0
        private void EntryUpdated(object sender, DailyEntry entry)
        {
            Dispatcher.BeginInvoke(() =>
            {
                if (entry != null)
                {
                    EntryDateTimeKeyTextBlock.Foreground =
                        BooleanToEntryHeaderColorConverter.Convert(entry.IsCompleted);
                }

                foreach (PivotItem pivotItem in EntryPagePivot.Items)
                {
                    var header = pivotItem.Header as TextBlock;
                    var index  = EntryPagePivot.Items.IndexOf(pivotItem);
                    if (header != null)
                    {
                        SetInactiveEntryPivotItemHeaderColour(header);
                        if (pivotItem == EntryPagePivot.SelectedItem)
                        {
                            SetActiveEntryPivotItemHeaderColour(header, index);
                        }
                    }
                }
            });
        }
Ejemplo n.º 3
0
        public void GetData(DateTime currentDataDateTimeKey)
        {
            Dictionary = DataManager.Instance.GetDailyEntriesData();

            if (Dictionary != null && Dictionary.ContainsKey(currentDataDateTimeKey))
            {
                DailyEntry = Dictionary[currentDataDateTimeKey].Clone();
            }
        }
Ejemplo n.º 4
0
            public void GetsAndSetsSteamId()
            {
                // Arrange -> Act
                var dailyEntry = new DailyEntry {
                    SteamId = 765
                };

                // Act -> Assert
                Assert.Equal(765L, dailyEntry.SteamId);
            }
Ejemplo n.º 5
0
            public void GetsAndSetsRank()
            {
                // Arrange -> Act
                var dailyEntry = new DailyEntry {
                    Rank = 345
                };

                // Act -> Assert
                Assert.Equal(345, dailyEntry.Rank);
            }
Ejemplo n.º 6
0
            public void GetsAndSetsLevel()
            {
                // Arrange -> Act
                var dailyEntry = new DailyEntry {
                    Level = 2
                };

                // Act -> Assert
                Assert.Equal(2, dailyEntry.Level);
            }
Ejemplo n.º 7
0
            public void GetsAndSetsZone()
            {
                // Arrange -> Act
                var dailyEntry = new DailyEntry {
                    Zone = 1
                };

                // Act -> Assert
                Assert.Equal(1, dailyEntry.Zone);
            }
Ejemplo n.º 8
0
            public void GetsAndSetsScore()
            {
                // Arrange -> Act
                var dailyEntry = new DailyEntry {
                    Score = 10
                };

                // Act -> Assert
                Assert.Equal(10, dailyEntry.Score);
            }
Ejemplo n.º 9
0
            public void GetsAndSetsLeaderboardId()
            {
                // Arrange -> Act
                var dailyEntry = new DailyEntry {
                    LeaderboardId = 234
                };

                // Act -> Assert
                Assert.Equal(234, dailyEntry.LeaderboardId);
            }
Ejemplo n.º 10
0
            public void GetsAndSetsReplayId()
            {
                // Arrange -> Act
                var dailyEntry = new DailyEntry {
                    ReplayId = 9082374
                };

                // Act -> Assert
                Assert.Equal(9082374L, dailyEntry.ReplayId);
            }
Ejemplo n.º 11
0
            public void GetsAndSetsLeaderboard()
            {
                // Arrange -> Act
                var leaderboard = new DailyLeaderboard();
                var dailyEntry  = new DailyEntry {
                    Leaderboard = leaderboard
                };

                // Act -> Assert
                Assert.Equal(leaderboard, dailyEntry.Leaderboard);
            }
Ejemplo n.º 12
0
            public void GetsAndSetsPlayer()
            {
                // Arrange -> Act
                var player     = new Player();
                var dailyEntry = new DailyEntry {
                    Player = player
                };

                // Act -> Assert
                Assert.Equal(player, dailyEntry.Player);
            }
    public async Task <IActionResult> Insert(DailyEntry dailyEntry)
    {
        try {
            var newDailyEntry = await _dailyEntryRepository.InsertAsync(dailyEntry);

            return(Created($"/daily-entries/{dailyEntry.Id}", newDailyEntry));
        }
        catch (Exception) {
            return(BadRequest());
        }
    }
    public async Task <IActionResult> Update(string id, DailyEntry updatedDailyEntry)
    {
        try {
            await _dailyEntryRepository.UpdateAsync(id, updatedDailyEntry);

            return(Ok($"The daily entry with id {id} has been updated"));
        }
        catch (Exception) {
            return(BadRequest());
        }
    }
Ejemplo n.º 15
0
            public void GetsAndSetsReplay()
            {
                // Arrange
                var replay     = new Replay();
                var dailyEntry = new DailyEntry();

                // Act
                dailyEntry.Replay = replay;
                var replay2 = dailyEntry.Replay;

                // Assert
                Assert.Same(replay, replay2);
            }
Ejemplo n.º 16
0
        public void Update(DailyEntry entry)
        {
            var item = GetTodayItem();

            if (item == null)
            {
                item       = CreateNew();
                item.Count = entry.Count;
                _database.Insert(item);
            }
            else
            {
                item.Count = entry.Count;
                _database.Update(item);
            }
        }
        public async Task WhenInsertFunctionIsCalled_IfValidId_ReturnsCreatedStatusAndInsertedEntry()
        {
            var entriesList = new List <DailyEntry>();

            entriesList.Add(new DailyEntry()
            {
                Id             = "entryid1",
                Date           = "2021-06-14",
                Topics         = "Testing1, xunit1",
                RecapQuizScore = 8,
            });
            entriesList.Add(new DailyEntry()
            {
                Id             = "entryid2",
                Date           = "2021-06-19",
                Topics         = "Testing2, xunit2",
                RecapQuizScore = 7,
            });

            DailyEntry testDailyEntry = new DailyEntry {
                Id             = "entryid3",
                Date           = "2021-06-24",
                Topics         = "Testing3, xunit3",
                RecapQuizScore = 9,
            };

            var mockRepository = new Mock <IRepository <DailyEntry> >();

            mockRepository.Setup(repo => repo.InsertAsync(It.IsAny <DailyEntry>()))
            .Callback(() => entriesList.Add(testDailyEntry))
            .Returns(() => Task.FromResult(entriesList.LastOrDefault()));

            var controller = new DailyEntryController(mockRepository.Object);

            var result = await controller.Insert(testDailyEntry);

            mockRepository.Verify(x => x.InsertAsync(It.IsAny <DailyEntry>()), Times.Once);

            var viewResult = Assert.IsType <CreatedResult>(result);
            var model      = Assert.IsType <DailyEntry>(viewResult.Value);

            Assert.Equal(201, viewResult.StatusCode);
            Assert.Equal(testDailyEntry.Date, model.Date);
            Assert.Equal(testDailyEntry.RecapQuizScore, model.RecapQuizScore);
            Assert.Equal(3, entriesList.Count);
        }
        public async void WhenInsertFunctionIsCalled_IfExceptionThrown_ReturnsBadRequestStatus()
        {
            var testDailyEntry = new DailyEntry()
            {
            };

            var mockRepository = new Mock <IRepository <DailyEntry> >();

            mockRepository.Setup(repo => repo.InsertAsync(testDailyEntry)).Throws(new Exception());

            var controller = new DailyEntryController(mockRepository.Object);

            var result = await controller.Insert(testDailyEntry);

            var viewResult = Assert.IsType <BadRequestResult>(result);

            Assert.Equal(400, viewResult.StatusCode);
        }
Ejemplo n.º 19
0
        public async void WhenUpdateFunctionIsCalled_IfValidId_ReturnsOkStatus()
        {
            string entryId   = "test";
            var    testEntry = new DailyEntry()
            {
            };
            var mockRepository = new Mock <IRepository <DailyEntry> >();

            mockRepository.Setup(repo => repo.UpdateAsync(entryId, testEntry)).Returns(Task.FromResult <DailyEntry>(testEntry));;

            var controller = new DailyEntryController(mockRepository.Object);

            var result = await controller.Update(entryId, testEntry);

            var viewResult = Assert.IsType <OkObjectResult>(result);
            var model      = viewResult.Value;

            Assert.Equal(200, viewResult.StatusCode);
            Assert.Equal(model, $"The daily entry with id {entryId} has been updated");
        }
Ejemplo n.º 20
0
        private void UpdateDailyForecast()
        {
            List <DailyEntry> dailies = oneCallRequest.OneCall.DailyEntries;

            for (int i = 0; i < dayWeatherViewModels.Count; i++)
            {
                DailyEntry daily   = dailies[i];
                Weather    weather = daily.WeatherEntries[0];

                Temperature temperatureHigh = new Temperature(daily.DailyTemperature.DailyHighCelsius, TemperatureFormat.Celsius);
                Temperature temperatureLow  = new Temperature(daily.DailyTemperature.DailyLowCelsius, TemperatureFormat.Celsius);

                DayWeatherViewModel vm = dayWeatherViewModels[i];
                vm.Date                      = FormatDateString(daily.DateTime);
                vm.Description               = GetFinalDescription(weather.Description);
                vm.TemperatureCelsiusLow     = string.Format("{0:0.00}", temperatureLow.Celsius);
                vm.TemperatureCelsiusHigh    = string.Format("{0:0.00}", temperatureHigh.Celsius);
                vm.TemperatureFahrenheitLow  = string.Format("{0:0.00}", temperatureLow.Fahrenheit);
                vm.TemperatureFahrenheitHigh = string.Format("{0:0.00}", temperatureHigh.Fahrenheit);
                vm.IconUrl                   = weather.GetIconUrl();
            }
        }