コード例 #1
0
        public async Task EnsureGetByMonthOnlyGetsRequestedMonthEntries()
        {
            using (var context = new EntitiesContext(dbInfo.ConnectionString))
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                {
                    var chore = context.Chores.Single();
                    ILogEntryService service = new LogEntryService(unitOfWork.RepositoryAsync <LogEntry>());
                    var controller           = new LogEntriesController(unitOfWork, service);

                    controller.SetControllerContext(HttpMethod.Post, "http://localhost/RowanAdams/api/logentries");
                    await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 1, 1) });

                    await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 1, 2) });

                    await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 1, 3) });

                    await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 2, 3) });

                    controller.SetControllerContext(HttpMethod.Get, $"http://localhost/RowanAdams/api/logentries/month");
                    var logEntries = await controller.GetByMonth(new DateTime(2015, 2, 1));

                    Assert.AreEqual(1, logEntries.Count());
                    var logEntry = logEntries.First();
                    Assert.AreEqual(chore.Id, logEntry.ChoreId);
                    Assert.AreEqual(chore.Name, logEntry.Name);
                    Assert.AreEqual(chore.Value, logEntry.Value);
                    Assert.AreEqual(new DateTime(2015, 2, 3), logEntry.CompletedDate);
                }
        }
コード例 #2
0
        public static async Task <object> Handle(string organizationId, RosterRequest request)
        {
            var logEntryService = new LogEntryService(organizationId);

            return(request.resource switch
            {
                "/log-entries" => request.httpMethod switch
                {
                    "GET" => await logEntryService.GetLogEntries(),
                    "PUT" => await logEntryService.SaveLogEntry(JsonSerializer.Deserialize <LogEntryModel>(request.body.GetRawText())),
                    _ => throw new ArgumentOutOfRangeException(ErrorHelper.InvalidHttpMethodForResource(request.httpMethod, request.resource)),
                },
コード例 #3
0
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            LogEntryService myLogEntryService = new LogEntryService();
            LogEntry selectedLogEntry = (e.OriginalSource as FrameworkElement).DataContext as LogEntry;

            _dao.DeleteLogEntry(selectedLogEntry);
            lstLogEntries.Remove(selectedLogEntry);

            myLogEntryService.RenumberLogEntries(selectedLogEntry, selectedLogEntry.LogDate);

            lstLogEntries = _dao.GetLogEntries(selectedLogEntry.ExerciseID);
            LogEntrieList.ItemsSource = lstLogEntries;
        }
コード例 #4
0
        public void TestDelete()
        {
            Mock <ILogEntryDao> logEntryDaoMock = new Mock <ILogEntryDao>();

            logEntryDaoMock.Setup(x => x.Delete(It.IsAny <LogEntry>()));

            LogEntry logEntry = new LogEntry();

            ILogEntryService logEntryService = new LogEntryService(logEntryDaoMock.Object);

            logEntryService.Delete(logEntry);

            logEntryDaoMock.Verify(x => x.Delete(logEntry), Times.Once);
        }
コード例 #5
0
        public void TestCreate()
        {
            Mock <ILogEntryDao> logDaoMock = new Mock <ILogEntryDao>();

            logDaoMock.Setup(x => x.Create(It.IsAny <Variation>(), It.IsAny <LogEntry>()));

            Variation fakeVariation = new Variation();

            ILogEntryService logService = new LogEntryService(logDaoMock.Object);

            logService.Create(fakeVariation, DateTime.Today, "freeclimb");

            logDaoMock.Verify(x => x.Create(fakeVariation, It.Is <LogEntry>(y => y.Memo == "freeclimb" && y.DateTime == DateTime.Today)), Times.Once);
        }
コード例 #6
0
		public async Task EnsurePostReturnsErrorWhenInvalidModel()
		{
			using (var context = new EntitiesContext(dbInfo.ConnectionString))
			using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
			{
				var chore = context.Chores.Single();
				ILogEntryService service = new LogEntryService(unitOfWork.RepositoryAsync<LogEntry>());
				var controller = new LogEntriesController(unitOfWork, service);
				controller.ModelState.AddModelError("TestError", new Exception());
				controller.SetControllerContext(HttpMethod.Post, "http://localhost/RowanAdams/api/logentries");
				var result = await controller.Post(new LogEntry { });
				var response = await result.ExecuteAsync(new CancellationToken());
				Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
			}
		}
コード例 #7
0
        public void TestGetAll()
        {
            Mock <ILogEntryDao> logDaoMock = new Mock <ILogEntryDao>();

            logDaoMock.Setup(x => x.GetAllIn(It.IsAny <Variation>())).Returns(new List <LogEntry> {
                new LogEntry()
            });

            Variation fakeVariation = new Variation();

            ILogEntryService logService      = new LogEntryService(logDaoMock.Object);
            IList <LogEntry> logsInVariation = logService.GetAllIn(fakeVariation);

            Assert.AreEqual(1, logsInVariation.Count);

            logDaoMock.Verify(x => x.GetAllIn(fakeVariation), Times.Once);
        }
コード例 #8
0
        public async Task EnsurePostReturnsErrorWhenInvalidModel()
        {
            using (var context = new EntitiesContext(dbInfo.ConnectionString))
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                {
                    var chore = context.Chores.Single();
                    ILogEntryService service = new LogEntryService(unitOfWork.RepositoryAsync <LogEntry>());
                    var controller           = new LogEntriesController(unitOfWork, service);
                    controller.ModelState.AddModelError("TestError", new Exception());
                    controller.SetControllerContext(HttpMethod.Post, "http://localhost/RowanAdams/api/logentries");
                    var result = await controller.Post(new LogEntry { });

                    var response = await result.ExecuteAsync(new CancellationToken());

                    Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
                }
        }
コード例 #9
0
        public async Task EnsureGetLogEntryGetsLogEntry()
        {
            using (var context = new EntitiesContext(dbInfo.ConnectionString))
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                {
                    var chore = context.Chores.Single();
                    ILogEntryService service = new LogEntryService(unitOfWork.RepositoryAsync <LogEntry>());
                    var controller           = new LogEntriesController(unitOfWork, service);

                    controller.SetControllerContext(HttpMethod.Post, "http://localhost/RowanAdams/api/logentries");
                    var result = await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 1, 1) });

                    var logEntry = context.LogEntries.Single();

                    controller.SetControllerContext(HttpMethod.Get, $"http://localhost/RowanAdams/api/logentries/{logEntry.Id}");
                    var logEntry2 = await controller.GetLogEntry(logEntry.Id);

                    Assert.AreEqual(logEntry.Id, logEntry2.Id);
                }
        }
コード例 #10
0
        public async Task EnsureGetAllGetsAllGroupedByMonthDescending()
        {
            using (var context = new EntitiesContext(dbInfo.ConnectionString))
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                {
                    var chore = context.Chores.Single();
                    ILogEntryService service = new LogEntryService(unitOfWork.RepositoryAsync <LogEntry>());
                    var controller           = new LogEntriesController(unitOfWork, service);

                    controller.SetControllerContext(HttpMethod.Post, "http://localhost/RowanAdams/api/logentries");
                    await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 1, 1) });

                    await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 1, 2) });

                    await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 1, 3) });

                    await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 2, 1) });

                    await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 2, 2) });

                    await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 2, 3) });

                    controller.SetControllerContext(HttpMethod.Get, $"http://localhost/RowanAdams/api/logentries/all");
                    var logEntries = await controller.GetAllGroupedByMonth();

                    Assert.AreEqual(2, logEntries.Count());
                    var logEntryGroup = logEntries.First();
                    Assert.AreEqual("February 2015", logEntryGroup.GroupName);
                    Assert.AreEqual(30, logEntryGroup.GroupTotal);
                    var logEntry = logEntryGroup.LogEntries.First();
                    Assert.AreEqual(chore.Id, logEntry.ChoreId);
                    Assert.AreEqual(chore.Name, logEntry.Name);
                    Assert.AreEqual(chore.Value, logEntry.Value);
                    Assert.AreEqual(new DateTime(2015, 2, 3), logEntry.CompletedDate);
                    logEntry = logEntryGroup.LogEntries.Skip(1).Take(1).First();
                    Assert.AreEqual(new DateTime(2015, 2, 2), logEntry.CompletedDate);
                    logEntry = logEntryGroup.LogEntries.Skip(2).Take(1).First();
                    Assert.AreEqual(new DateTime(2015, 2, 1), logEntry.CompletedDate);
                }
        }
コード例 #11
0
		public async Task EnsurePostCreatesNewLogEntryAndSetsHttpStatus()
		{
			using (var context = new EntitiesContext(dbInfo.ConnectionString))
			using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
			{
				var chore = context.Chores.Single();
				ILogEntryService service = new LogEntryService(unitOfWork.RepositoryAsync<LogEntry>());
				var controller = new LogEntriesController(unitOfWork, service);
					
				controller.SetControllerContext(HttpMethod.Post, "http://localhost/RowanAdams/api/logentries");
				var result = await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 1, 1)});
				var response = await result.ExecuteAsync(new CancellationToken());

				Assert.AreEqual(1, context.LogEntries.Count());
				var logEntry = context.LogEntries.Single();
				Assert.AreNotEqual(Guid.Empty, logEntry.Id);
				Assert.AreEqual(chore.Id, logEntry.ChoreId);
				Assert.AreEqual(new DateTime(2015, 1, 1), logEntry.CompletedDate);
				Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
				Assert.AreEqual($"/api/logentries/{logEntry.Id}", response.Headers.Location.AbsolutePath);
			}
		}
コード例 #12
0
        public async Task EnsurePostCreatesNewLogEntryAndSetsHttpStatus()
        {
            using (var context = new EntitiesContext(dbInfo.ConnectionString))
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                {
                    var chore = context.Chores.Single();
                    ILogEntryService service = new LogEntryService(unitOfWork.RepositoryAsync <LogEntry>());
                    var controller           = new LogEntriesController(unitOfWork, service);

                    controller.SetControllerContext(HttpMethod.Post, "http://localhost/RowanAdams/api/logentries");
                    var result = await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 1, 1) });

                    var response = await result.ExecuteAsync(new CancellationToken());

                    Assert.AreEqual(1, context.LogEntries.Count());
                    var logEntry = context.LogEntries.Single();
                    Assert.AreNotEqual(Guid.Empty, logEntry.Id);
                    Assert.AreEqual(chore.Id, logEntry.ChoreId);
                    Assert.AreEqual(new DateTime(2015, 1, 1), logEntry.CompletedDate);
                    Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
                    Assert.AreEqual($"/api/logentries/{logEntry.Id}", response.Headers.Location.AbsolutePath);
                }
        }
コード例 #13
0
        public async Task ShouldReturnSuccessfullyWhenAddingToLog()
        {
            string logUrl = "http://api.dev.geonorge.no/endringslogg/";

            Utilities.LogEntry.LogEntry log = new Utilities.LogEntry.LogEntry
            {
                Application = "Register",
                User        = "******",
                Description = "testing logging",
                ElementId   = "83f9cca1-8cf3-41c7-b55b-c80bbcca3dfa"
            };

            const string content =
                @"{Application:""Register"", User:""demobruker"", Description:""testing logging"",ElementId : ""83f9cca1-8cf3-41c7-b55b-c80bbcca3dfa"" }";
            var httpClient = CreateHttpClientFactory(HttpStatusCode.NoContent, content);

            LogEntryService service          = new LogEntryService(logUrl, apiKey, httpClient);
            HttpStatusCode  actualStatusCode = await service.AddLogEntry(log);

            var expectedStatusCode = HttpStatusCode.NoContent;

            Assert.Equal(expectedStatusCode, actualStatusCode);
        }
コード例 #14
0
		public async Task EnsureGetAllGetsAllGroupedByMonthDescending()
		{
			using (var context = new EntitiesContext(dbInfo.ConnectionString))
			using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
			{
				var chore = context.Chores.Single();
				ILogEntryService service = new LogEntryService(unitOfWork.RepositoryAsync<LogEntry>());
				var controller = new LogEntriesController(unitOfWork, service);

				controller.SetControllerContext(HttpMethod.Post, "http://localhost/RowanAdams/api/logentries");
				await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 1, 1) });
				await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 1, 2) });
				await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 1, 3) });
				await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 2, 1) });
				await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 2, 2) });
				await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 2, 3) });

				controller.SetControllerContext(HttpMethod.Get, $"http://localhost/RowanAdams/api/logentries/all");
				var logEntries = await controller.GetAllGroupedByMonth();

				Assert.AreEqual(2, logEntries.Count());
				var logEntryGroup = logEntries.First();
				Assert.AreEqual("February 2015", logEntryGroup.GroupName);
				Assert.AreEqual(30, logEntryGroup.GroupTotal);
				var logEntry = logEntryGroup.LogEntries.First();
				Assert.AreEqual(chore.Id, logEntry.ChoreId);
				Assert.AreEqual(chore.Name, logEntry.Name);
				Assert.AreEqual(chore.Value, logEntry.Value);
				Assert.AreEqual(new DateTime(2015, 2, 3), logEntry.CompletedDate);
				logEntry = logEntryGroup.LogEntries.Skip(1).Take(1).First();
				Assert.AreEqual(new DateTime(2015, 2, 2), logEntry.CompletedDate);
				logEntry = logEntryGroup.LogEntries.Skip(2).Take(1).First();
				Assert.AreEqual(new DateTime(2015, 2, 1), logEntry.CompletedDate);
			}
		}
コード例 #15
0
		public async Task EnsureGetLogEntryGetsLogEntry()
		{
			using (var context = new EntitiesContext(dbInfo.ConnectionString))
			using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
			{
				var chore = context.Chores.Single();
				ILogEntryService service = new LogEntryService(unitOfWork.RepositoryAsync<LogEntry>());
				var controller = new LogEntriesController(unitOfWork, service);

				controller.SetControllerContext(HttpMethod.Post, "http://localhost/RowanAdams/api/logentries");
				var result = await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 1, 1) });
				var logEntry = context.LogEntries.Single();

				controller.SetControllerContext(HttpMethod.Get, $"http://localhost/RowanAdams/api/logentries/{logEntry.Id}");
				var logEntry2 = await controller.GetLogEntry(logEntry.Id);

				Assert.AreEqual(logEntry.Id, logEntry2.Id);
			}
		}
コード例 #16
0
		public async Task EnsureGetByMonthOnlyGetsRequestedMonthEntries()
		{
			using (var context = new EntitiesContext(dbInfo.ConnectionString))
			using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
			{
				var chore = context.Chores.Single();
				ILogEntryService service = new LogEntryService(unitOfWork.RepositoryAsync<LogEntry>());
				var controller = new LogEntriesController(unitOfWork, service);

				controller.SetControllerContext(HttpMethod.Post, "http://localhost/RowanAdams/api/logentries");
				await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 1, 1) });
				await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 1, 2) });
				await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 1, 3) });
				await controller.Post(new LogEntry { ChoreId = chore.Id, CompletedDate = new DateTime(2015, 2, 3) });

				controller.SetControllerContext(HttpMethod.Get, $"http://localhost/RowanAdams/api/logentries/month");
				var logEntries = await controller.GetByMonth(new DateTime(2015, 2, 1));

				Assert.AreEqual(1, logEntries.Count());
				var logEntry = logEntries.First();
				Assert.AreEqual(chore.Id, logEntry.ChoreId);
				Assert.AreEqual(chore.Name, logEntry.Name);
				Assert.AreEqual(chore.Value, logEntry.Value);
				Assert.AreEqual(new DateTime(2015, 2, 3), logEntry.CompletedDate);
			}
		}
コード例 #17
0
 public LogEntryController(LogEntryService logEntryService)
 {
     _logEntryService = logEntryService;
 }