Example #1
0
        public void List()
        {
            // Arrange
            var mapper = Substitute.For <IMapper>();
            var repo   = Substitute.For <IRepository>();

            repo.ListRecords().Returns(x =>
            {
                return(new List <Model.Record>()
                {
                    new Model.Record {
                        ApplicationName = "appName",
                        DataType = "dataType",
                        Value = "test",
                        Version = "1.0",
                    }
                });
            });
            var logger = Substitute.For <ILogger <RecordsController> >();

            var target = new RecordsController(repo, logger, mapper);

            // Act
            var result = target.List();

            // Assert
            Assert.IsType <OkObjectResult>(result);
        }
Example #2
0
        public void List_Throws()
        {
            // Arrange
            var mapper = Substitute.For <IMapper>();
            var repo   = Substitute.For <IRepository>();

            repo.ListRecords().Returns(x => { throw new System.Exception("Boom"); });
            var logger = Substitute.For <ILogger <RecordsController> >();

            var target = new RecordsController(repo, logger, mapper);

            // Act
            var result = target.List();

            // 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);
        }