Beispiel #1
0
        public void Post_Update()
        {
            // Arrange
            var recordContract = new RecordContract
            {
                ApplicationName = "testAppName",
                DataType        = "dataType",
                Version         = "version1",
                Value           = "value",
                DateCreated     = DateTime.UtcNow,
                DateModified    = DateTime.UtcNow
            };

            var req = new MockHttpRequest
            {
                Body = RecordFunctionTests.GenerateStreamFromString(_record)
            };
            var mapper = Substitute.For <IMapper>();
            var repo   = Substitute.For <IRepository>();

            repo.UpsertRecord(Arg.Any <Model.Record>()).Returns(Task.FromResult <Model.Record>(new Model.Record
            {
                DateModified = DateTime.Now
            }));

            var logger = Substitute.For <ILogger <Records> >();

            var target = new Records(repo, mapper);

            // Act
            var result = target.Post(req, logger).Result;

            // Assert
            Assert.IsType <OkObjectResult>(result);
        }
Beispiel #2
0
        public void Post_Throws()
        {
            // Arrange
            var recordContract = new RecordContract
            {
                ApplicationName = "testAppName",
                DataType        = "dataType",
                Version         = "version1",
                Value           = "value",
                DateCreated     = DateTime.UtcNow,
                DateModified    = DateTime.UtcNow
            };

            var req = new MockHttpRequest
            {
                Body = RecordFunctionTests.GenerateStreamFromString(_record)
            };

            var mapper = Substitute.For <IMapper>();
            var repo   = Substitute.For <IRepository>();

            repo.UpsertRecord(Arg.Any <Model.Record>()).Returns(Task.FromException <Model.Record>(new System.Exception("Boom")));
            var logger = Substitute.For <ILogger <Records> >();

            var target = new Records(repo, mapper);

            // Act
            var result = target.Post(req, logger).Result;

            // Assert
            logger.Received().Log(
                LogLevel.Error,
                Arg.Any <EventId>(),
                Arg.Is <object>(o => o.ToString() == "Boom"),
                null,
                Arg.Any <Func <object, Exception, string> >());

            Assert.IsType <BadRequestObjectResult>(result);
        }