コード例 #1
0
 public IActionResult GetAllSync()
 {
     return(new JsonResult(
                new
     {
         body = new
         {
             result = "Success",
             message = "",
             data = IranianMusicIstrumentsRepository.GetAllFormal()
         },
         status = 200
     }));
 }
コード例 #2
0
        public void ItHandlesValidAndFormalInstrumentName()
        {
            // Arange
            const string instrument = "Tar";

            var tarDescription = IranianMusicIstrumentsRepository.GetFormalInstrumentDescription(instrument);

            //Mocking ProviderService
            //1-Provider State
            //2-Description for Specified Provider State
            //3-Specifing the Request
            //4-The Desired Response for Specified Request

            _mockProviderService
            .Given("Instrument is Formal")
            .UponReceiving("A valid GET request for Instruments with successfully response")
            .With(new ProviderServiceRequest
            {
                Method = HttpVerb.Get,
                Path   = "/api/Instrument",
                Query  = $"name={instrument}"
            })
            .WillRespondWith(new ProviderServiceResponse
            {
                Status  = 200,
                Headers = new Dictionary <string, object>
                {
                    { "Content-Type", "application/json; charset=utf-8" }
                },
                Body = new
                {
                    message = "",
                    result  = "Success",
                    data    = tarDescription
                }
            });

            // Act
            var result = HttpUtility.GetInstrumentDesc(instrument, _baseUri)
                         .GetAwaiter()
                         .GetResult();

            var resultBodyText = result.Content.ReadAsStringAsync()
                                 .GetAwaiter()
                                 .GetResult();

            // Assert
            Assert.Contains(tarDescription.Substring(0, 30), resultBodyText); //Very simple assertion to assert if response message contains expected result.
        }
コード例 #3
0
        public void ItHandlesGetAllInstruments()
        {
            // Arange
            var instruments = IranianMusicIstrumentsRepository.GetAllFormal();

            //Mocking ProviderService
            //1-Provider State
            //2-Description for Specified Provider State
            //3-Specifing the Request
            //4-The Desired Response for Specified Request

            _mockProviderService
            .Given("Get All Instruments")
            .UponReceiving("A valid GET request for all Instruments with successfully response")
            .With(new ProviderServiceRequest
            {
                Method = HttpVerb.Get,
                Path   = "/api/Instrument"
            })
            .WillRespondWith(new ProviderServiceResponse
            {
                Status  = 200,
                Headers = new Dictionary <string, object>
                {
                    { "Content-Type", "application/json; charset=utf-8" }
                },
                Body = new
                {
                    message = "",
                    result  = "Suucess",
                    data    = instruments
                }
            });

            // Act
            var result = HttpUtility.GetAllInstruments(_baseUri)
                         .GetAwaiter()
                         .GetResult();

            var resultBodyText = result.Content.ReadAsStringAsync()
                                 .GetAwaiter()
                                 .GetResult();
            var deserializeObject = JsonConvert.DeserializeObject <ResponseVM>(resultBodyText);

            // Assert
            Assert.Equal(instruments.Count, deserializeObject.data.Count); //Very simple assertion to assert if response message contains expected result.
        }
コード例 #4
0
        public IActionResult GetSync(string name)
        {
            if (IranianMusicIstrumentsRepository.HasFormalInstrument(name))
            {
                return(new JsonResult(
                           new
                {
                    result = "Success",
                    data = IranianMusicIstrumentsRepository.GetFormalInstrumentDescription(name)
                }));
            }

            if (IranianMusicIstrumentsRepository.HasSecoundaryInstrument(name))
            {
                return(BadRequest(new
                {
                    message = $"{name} is a secoundary Instrument",
                }));
            }

            return(NotFound());
        }