Пример #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"));
        }
Пример #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 GetStatuses_ShouldReturnStatuses()
        {
            // Arrange
            var statusesRepository = new MockStatusesRepository();
            var controller         = new StatusesController(statusesRepository)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

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

            // Assert
            Assert.IsNotNull(response);

            List <Status> statuses;

            Assert.IsTrue(response.TryGetContentValue(out statuses));
            Assert.AreEqual(statuses.Count, 4);
        }