Beispiel #1
0
        public void PostSample_MissingBarcode_ShouldReturnError()
        {
            // Arrange
            var statusesRepository = new MockStatusesRepository();
            var usersRepository    = new MockUsersRepository();
            var samplesRepository  = new MockSamplesRepository();
            var controller         = new SamplesController(statusesRepository, samplesRepository, usersRepository)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };
            var sampleToSave = new SampleDto
            {
                CreatedAt   = DateTime.Now,
                CreatedById = 0,
                StatusId    = 2
            };

            // Act
            var response = controller.Post(sampleToSave);

            // Assert
            Assert.IsNotNull(response);
            Assert.AreEqual(response.StatusCode, System.Net.HttpStatusCode.BadRequest);

            HttpError error;

            Assert.IsTrue(response.TryGetContentValue(out error));
            Assert.IsTrue(error.Message.Contains("Barcode is required"));
        }
Beispiel #2
0
        public void PostSample_ValidSample_ShouldSucceed()
        {
            // Arrange
            var statusesRepository   = new MockStatusesRepository();
            var usersRepository      = new MockUsersRepository();
            var samplesRepository    = new MockSamplesRepository();
            var originalSamplesCount = samplesRepository.GetSamples().Count;
            var controller           = new SamplesController(statusesRepository, samplesRepository, usersRepository)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };
            var sampleToSave = new SampleDto
            {
                Barcode     = "JVN002",
                CreatedAt   = DateTime.Now,
                CreatedById = 0,
                StatusId    = 2
            };

            // Act
            var response = controller.Post(sampleToSave);

            // Assert
            Assert.IsNotNull(response);
            Assert.AreNotEqual(0, response.Content);
            var newSamples = samplesRepository.GetSamples();

            Assert.AreEqual(originalSamplesCount + 1, newSamples.Count);
        }
        public void GetUsers_ShouldReturnUsers()
        {
            // Arrange
            var usersRepository = new MockUsersRepository();
            var controller      = new UsersController(usersRepository)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            // Act
            var response = controller.Get();

            // Assert
            Assert.IsNotNull(response);

            List <User> users;

            Assert.IsTrue(response.TryGetContentValue(out users));
            Assert.AreEqual(users.Count, 1);
        }
Beispiel #4
0
        public void GetSamples_ShouldReturnSampleDtos()
        {
            // Arrange
            var statusesRepository = new MockStatusesRepository();
            var usersRepository    = new MockUsersRepository();
            var samplesRepository  = new MockSamplesRepository();
            var controller         = new SamplesController(statusesRepository, samplesRepository, usersRepository)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            // Act
            var response = controller.Get();

            // Assert
            Assert.IsNotNull(response);

            List <SampleDto> samples;

            Assert.IsTrue(response.TryGetContentValue(out samples));
            Assert.AreEqual(samples.Count, 1);
        }