コード例 #1
0
        public void ValidateSampleDtoWithValidNameSucceeds()
        {
            // Arrange
            var sampleDto = new SampleDto()
            {
                Name = SAMPLE_DTO_NAME
            };

            // Act
            sampleDto.Validate();

            // Arrange
        }
コード例 #2
0
        public void ValidateSampleDtoWithInvalidNameThrowsContractException()
        {
            // Arrange
            var sampleDto = new SampleDto()
            {
                Name = " "
            };

            // Act
            sampleDto.Validate();

            // Arrange
        }
コード例 #3
0
        public async Task <SampleDto> Execute(SampleDto sampleDto)
        {
            Amostra amostra = SampleDtoMapToAmostra.Map(new Amostra(), sampleDto);

            if (amostra == null)
            {
                throw new AppError("Informe uma solicitação válida.");
            }
            _amostraRepository.Save(amostra);
            await _amostraRepository.Commit();

            return(sampleDto);
        }
コード例 #4
0
        public void View__Test()
        {
            var dto = new SampleDto();

            var modelstate = new ModelStateDictionary();

            modelstate.AddModelError(key: nameof(dto.FullName), errorMessage: $"{ nameof(dto.FullName) } is required");

            var result = Generator.View(dto.InitialElements(dto), modelstate);

            Assert.IsTrue(condition: result.Contains(value: "<input") && result.Contains(value: nameof(dto.FullName)));

            Assert.IsTrue(condition: result.Contains(value: "<span"));
        }
コード例 #5
0
ファイル: TransientService.cs プロジェクト: VoBilyk/Watcher
        public Task <SampleDto> GenerateRandomSampleDtoAsync()
        {
            // Initate asynchonous call
            return(Task.Run(
                       () =>
            {
                var randomNumber = _random.Next(0, 100000);         //for ints
                var randomEnum = _random.Next((int)SampleEnum.FirstItem, (int)SampleEnum.ThirdItem);
                var name = GetGeneratedNumber();
                var sample = new SampleDto(randomNumber, (SampleEnum)randomEnum, name);

                return sample;
            }));
        }
コード例 #6
0
        public void GetValidationResultsForSampleDtoWithInvalidNameReturnsListOfResults()
        {
            // Arrange
            var sampleDto = new SampleDto()
            {
                Name = " "
            };

            // Act
            var validationResults = sampleDto.GetValidationResults();

            // Arrange
            Assert.AreEqual(1, validationResults.Count);
        }
コード例 #7
0
        public void IsValidForSampleDtoWithValidNameReturnsTrue()
        {
            // Arrange
            var sampleDto = new SampleDto()
            {
                Name = SAMPLE_DTO_NAME
            };

            // Act
            var isValid = sampleDto.IsValid();

            // Assert
            Assert.IsTrue(isValid);
        }
コード例 #8
0
 public IActionResult OnGet()
 {
     _sampleDto        = new SampleDto();
     _sampleDto.Assays = new List <AssayDto>();
     _sampleDto.Assays.Add(new AssayDto(EnumAssay.M02, 2));
     _sampleDto.Assays.Add(new AssayDto(EnumAssay.M06, 4));
     _sampleDto.Assays.Add(new AssayDto(EnumAssay.M07, 5));
     _sampleDto.Assays.Add(new AssayDto(EnumAssay.M13, 8));
     _sampleDto.Assays.Add(new AssayDto(EnumAssay.M15, 10));
     _sampleDto.Assays.Add(new AssayDto(EnumAssay.M15L, 11));
     _sampleDto.Assays.Add(new AssayDto(EnumAssay.M16, 12));
     _sampleDto.Assays.Add(new AssayDto(EnumAssay.M16L, 13));
     return(Page());
 }
コード例 #9
0
        public void SerializeSampleDtoReturnsJsonRepresentationOfSampleDto()
        {
            // Arrange
            var sampleDto = new SampleDto()
            {
                Name = SAMPLE_DTO_NAME
            };

            // Act
            var serializationResult = sampleDto.SerializeObject();

            // Assert
            Assert.AreEqual(SAMPLE_DTO_JSON_REPRESENTATION, serializationResult);
        }
コード例 #10
0
        public void GetValidationResultsForSampleDtoWithValidNameReturnsEmptyList()
        {
            // Arrange
            var sampleDto = new SampleDto()
            {
                Name = SAMPLE_DTO_NAME
            };

            // Act
            var validationResults = sampleDto.GetValidationResults();

            // Arrange
            Assert.AreEqual(0, validationResults.Count);
        }
コード例 #11
0
        public async Task <IActionResult> ImportNew(SampleDto model)
        {
            var result = new HttpResult <System.Collections.Generic.List <SampleDto> >(this._logger);

            try
            {
                var returnModel = await this._app.ImportNew(model);

                return(result.ReturnCustomResponse(this._app, returnModel));
            }
            catch (Exception ex)
            {
                return(result.ReturnCustomException(ex, "Seed - Sample", errorMap: new ErrorMapCustom()));
            }
        }
コード例 #12
0
        public int Save(SampleDto sampleDto)
        {
            var sample = new Sample
            {
                SampleId  = _samples.Count,
                Barcode   = sampleDto.Barcode,
                CreatedAt = sampleDto.CreatedAt,
                CreatedBy = sampleDto.CreatedById,
                StatusId  = sampleDto.StatusId
            };

            _samples.Add(sample);

            return(sample.SampleId);
        }
        public async Task <IActionResult> Delete(SampleDto dto)
        {
            var result = new HttpResult <SampleDto>(this._logger);

            try
            {
                await this._app.Remove(dto);

                return(result.ReturnCustomResponse(this._app, dto));
            }
            catch (Exception ex)
            {
                return(result.ReturnCustomException(ex, "Seed - Sample", dto));
            }
        }
コード例 #14
0
        public async Task <SampleDto> Execute(SampleDto sampleDto, int?solicitationId)
        {
            if (solicitationId <= 0)
            {
                throw new AppError("Informe uma solicitação válida.");
            }
            Solicitacao solicitacao = await _solicitacaoRepository.GetByID((int)solicitationId);

            if (solicitacao == null)
            {
                throw new AppError("Informe uma solicitação válida.");
            }
            if (sampleDto.CollectionDate > DateTime.Now)
            {
                throw new AppError("Data de coleta não pode ser uma data futura");
            }
            if (sampleDto.FabricationDate > DateTime.Now)
            {
                throw new AppError("Data de fabricação não pode ser uma data futura");
            }
            if (sampleDto.FabricationDate > sampleDto.ExpirationDate)
            {
                throw new AppError("Data de fabricação não pode ser maior que a data de validade");
            }
            if (sampleDto.FabricationDate > sampleDto.CollectionDate)
            {
                throw new AppError("Data de fabricação não pode ser maior que a data de coleta");
            }
            Amostra amostra = SampleDtoMapToAmostra.Map(new Amostra(), sampleDto);

            amostra.fkSolicitacao   = solicitacao;
            amostra.fkSolicitacaoId = solicitacao.Id;
            _amostraRepository.Insert(amostra);
            await _amostraRepository.Commit();

            foreach (var x in sampleDto.Assays)
            {
                var ensaiosPorAmostra = new EnsaiosPorAmostra();
                ensaiosPorAmostra.fkAmostraId = amostra.Id;
                ensaiosPorAmostra.fkEnsaioId  = (int)x.Id;
                amostra.EnsaiosPorAmostras.Add(ensaiosPorAmostra);
            }
            sampleDto.Id = amostra.Id;
            _amostraRepository.Save(amostra);
            await _amostraRepository.Commit();

            return(sampleDto);
        }
コード例 #15
0
        public static SampleModel Map(int userId, SampleDto sampleDto)
        {
            if (sampleDto == null)
            {
                return(null);
            }

            return(new SampleModel(userId, sampleDto.DocumentNr)
            {
                Name = sampleDto.Name,
                Address = sampleDto.Address,
                City = sampleDto.City,
                Country = sampleDto.Country,
                PhoneNumbers = sampleDto.PhoneNumbers
            });
        }
コード例 #16
0
        public static Amostra Map(Amostra amostra, SampleDto sampleDto)
        {
            amostra.Id             = sampleDto.Id;
            amostra.Descricao      = sampleDto.Description;
            amostra.Lote           = sampleDto.Lot;
            amostra.DataColeta     = sampleDto.CollectionDate;
            amostra.DataFabricacao = sampleDto.FabricationDate;
            amostra.DataValidade   = sampleDto.ExpirationDate;

            amostra.Oficio      = sampleDto.Calling;
            amostra.TAA         = sampleDto.TAA;
            amostra.Lacre       = sampleDto.Seal;
            amostra.Temperatura = sampleDto.Temperature;

            return(amostra);
        }
コード例 #17
0
        public Task <Tuple <IEnumerable <SampleDto>, long> > FindAsync(
            string id, string description, int pageIndex, int pageSize)
        {
            bool Predicate(KeyValuePair <string, Sample> x) =>
            (string.IsNullOrEmpty(id) || x.Key == id) &&
            (string.IsNullOrEmpty(description) || x.Value.Description == description);

            List <SampleDto> dtos = _db.Where(Predicate)
                                    .Skip((pageIndex - 1) * pageSize)
                                    .Take(pageSize)
                                    .Select(x => SampleDto.FromEntity(x.Value))
                                    .ToList();

            int count = _db.Count(Predicate);

            return(Task.FromResult(new Tuple <IEnumerable <SampleDto>, long>(dtos, count)));
        }
コード例 #18
0
ファイル: SampleProviderTest.cs プロジェクト: FvdG/Socres
        public void SampleProvider_ExecuteWithDto_Succeeds(
            ISampleService sampleService,
            SampleDto dto,
            string returnValue)
        {
            A.CallTo(() => sampleService.CanExecute)
            .Returns(true);
            A.CallTo(() => sampleService.ExecuteWithDto(dto))
            .Returns(returnValue);

            var sampleProvider = new SampleProvider(sampleService);
            var actual         = sampleProvider.ExecuteSampleWithDto(dto);

            A.CallTo(() => sampleService.ExecuteWithDto(A <SampleDto> .Ignored))
            .MustHaveHappened(Repeated.Exactly.Once);
            Assert.Equal(returnValue, actual);
        }
コード例 #19
0
        public int Save(SampleDto sampleDto)
        {
            using (var context = new Entities())
            {
                var sample = new Sample
                {
                    Barcode   = sampleDto.Barcode,
                    CreatedAt = sampleDto.CreatedAt,
                    CreatedBy = sampleDto.CreatedById,
                    StatusId  = sampleDto.StatusId
                };
                context.Samples.Add(sample);
                context.SaveChanges();

                return(sample.SampleId);
            }
        }
コード例 #20
0
        public LineParametersDto(SampleDto firstSample, SampleDto secondSample, bool leftBounded, bool rightBounded)
        {
            ExceptionHelper.CheckArgumentNull(firstSample, "firstSample");
            ExceptionHelper.CheckArgumentNull(secondSample, "secondSample");
            if (firstSample.Concentration == secondSample.Concentration)
            {
                throw new ArgumentException("Samples must not have equal concentrations");
            }
            else
            {
                //ok
            }

            this.FirstSample  = firstSample;
            this.SecondSample = secondSample;
            this.LeftBounded  = leftBounded;
            this.RightBounded = rightBounded;
        }
コード例 #21
0
        public async Task <IActionResult> Delete(int id, SampleDto dto)
        {
            var result = new HttpResult <SampleDto>(this._logger);

            try
            {
                if (id.IsSent())
                {
                    dto.SampleId = id;
                }
                await this._app.Remove(dto);

                return(result.ReturnCustomResponse(this._app, dto));
            }
            catch (Exception ex)
            {
                return(result.ReturnCustomException(ex, "Seed - Sample", dto, new ErrorMapCustom()));
            }
        }
コード例 #22
0
        public void SampleProvider_ExecuteWithDto_CanExecute_Succeeds(
            bool canExecute,
            string returnValue,
            ISampleService sampleService,
            SampleDto dto)
        {
            // Arrange
            A.CallTo(() => sampleService.CanExecute)
            .Returns(canExecute);
            A.CallTo(() => sampleService.ExecuteWithDto(dto))
            .Returns(returnValue);
            var sampleProvider = new SampleProvider(sampleService);

            // Act
            var actual = sampleProvider.ExecuteSampleWithDto(dto);

            // Assert
            A.CallTo(() => sampleService.ExecuteWithDto(A <SampleDto> .Ignored))
            .MustHaveHappenedANumberOfTimesMatching(n => n == (canExecute ? 1 : 0));
            Assert.Equal(returnValue, actual);
        }
コード例 #23
0
        private void InitializeCalibrationCurvePieces(IEnumerable <SampleDto> calibrationSamples)
        {
            IList <LinearFunctionParametersDto>  calibrationCurvePieces  = new List <LinearFunctionParametersDto>();
            LinearFunctionParametersDtoConverter linearFunctionConverter = new LinearFunctionParametersDtoConverter();

            calibrationSamples = calibrationSamples.OrderBy(x => x.Concentration);
            int samplesCount = calibrationSamples.Count();

            for (int i = 0; i < samplesCount - 1; i++)
            {
                SampleDto         sample1        = calibrationSamples.ElementAt(i);
                SampleDto         sample2        = calibrationSamples.ElementAt(i + 1);
                bool              leftBounded    = i == 0 ? false : true;
                bool              rightBounded   = i == samplesCount - 2 ? false : true;
                LineParametersDto lineParameters = new LineParametersDto(sample1, sample2, leftBounded, rightBounded);

                calibrationCurvePieces.Add(linearFunctionConverter.Convert(lineParameters));
            }

            this.calibrationCurvePieces = calibrationCurvePieces;
        }
コード例 #24
0
        public async void InsertHandler_Should_Work(string id, string description, bool expected)
        {
            // Given
            IMediator mediator = ServiceProvider.GetService <IMediator>();

            MockEventPublisher   publisher  = new MockEventPublisher(mediator);
            MockSampleRepository repository =
                new MockSampleRepository(new Dictionary <string, Domain.Sample.Sample>());
            Mock <IUnitOfWork> uow                 = new Mock <IUnitOfWork>();
            MockSampleService  service             = new MockSampleService();
            Mock <ILogger <InsertRequest> > logger = new Mock <ILogger <InsertRequest> >();

            InsertHandler handler =
                new InsertHandler(publisher, repository, uow.Object, service, logger.Object);

            SampleDto item = new SampleDto {
                Id = id, Description = description
            };
            InsertRequest command = new InsertRequest(item);

            // When
            EntityResult <SampleDto> result = await handler.Handle(command, new CancellationToken());

            // Then
            List <ValidationResult> notValidNotifications =
                result.Notifications.Where(notification => !notification.IsValid).ToList();

            if (expected)
            {
                Assert.Empty(notValidNotifications);
                Assert.True(ContainsType(publisher.Notifications,
                                         typeof(DomainEvent <InsertRequest>)));
            }
            else
            {
                Assert.NotEmpty(notValidNotifications);
                Assert.False(ContainsType(publisher.Notifications,
                                          typeof(DomainEvent <InsertRequest>)));
            }
        }
コード例 #25
0
        public EvaluationResult Evaluate(SampleDto sample)
        {
            ExceptionHelper.CheckArgumentNull(sample, "sample");

            EvaluationResult evaluationResult;

            double calibrationCurveValue = this.calibrationCurve.GetValue(sample.Concentration);

            if (sample.Value > calibrationCurveValue)
            {
                evaluationResult = EvaluationResult.POSITIVE;
            }
            else if (sample.Value < calibrationCurveValue)
            {
                evaluationResult = EvaluationResult.NEGATIVE;
            }
            else
            {
                evaluationResult = EvaluationResult.INDEFINITE;
            }

            return(evaluationResult);
        }
コード例 #26
0
      private static async Task EnumLiteralTest(string enumLiteral)
      {
          HttpClient client = new HttpClient();

          client.DefaultRequestHeaders.Accept.Clear();
          client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

          SampleDto dto                = null;
          string    uriString          = $"{InProcess.LocalHttp}/{RoutePrefix}/{nameof(SampleDto)}?$filter={nameof(dto.@enum)} eq {enumLiteral}";
          Task <HttpResponseMessage> a = client.GetAsync(new Uri(uriString));

          a.Should().NotBeNull();
          HttpResponseMessage response = await a;

          response.Should().NotBeNull();

          var s = await response.Content.ReadAsStringAsync();

          response.IsSuccessStatusCode.Should().BeTrue(s.Replace("{", "{{").Replace("}", "}}"));
          TResult result = await response.Content.ReadAsAsync <TResult>();

          result.Should().NotBeNull().And.BeOfType <TResult>();
      }
コード例 #27
0
        public void SampleProvider_ExecuteWithDto_CanExecute_Succeeds(
            bool canExecute,
            string returnValue,
            ISampleService sampleService,
            SampleDto dto)
        {
            // Arrange
            A.CallTo(() => sampleService.CanExecute)
            .Returns(canExecute);
            A.CallTo(() => sampleService.ExecuteWithDto(dto))
            .Returns(returnValue);
            var sampleProvider = new SampleProvider(sampleService);

            // Act
            var actual = sampleProvider.ExecuteSampleWithDto(dto);

            // Assert
            A.CallTo(() => sampleService.ExecuteWithDto(A <SampleDto> .Ignored))
            .MustHaveHappened(
                canExecute
                    ? Repeated.Exactly.Once
                    : Repeated.Never);
            Assert.Equal(returnValue, actual);
        }
コード例 #28
0
 public (SampleDto, bool?, SampleException) Update(int userId, SampleDto data)
 {
     (var result, var status, var error) = _sampleRepository.Update(SampleMapper.Map(userId, data));
     return(SampleMapper.Map(result), status, error);
 }
コード例 #29
0
 public IActionResult Delete(SampleDto dto)   //默认从Body取参数
 {
     return(Json(new { data = $"id:{dto.Id}, name :{dto.Name}" }));
 }
コード例 #30
0
 public IActionResult Put(SampleDto dto)   //Put默认在Body取参数出来,需要在Url或FormData传参,需要指定 [FromQuery]
 {
     return(Json(new { data = $"id:{dto.Id}, name :{dto.Name}" }));
 }