示例#1
0
        public async Task GetAllCowsAsync()
        {
            await DataBaseHelper.ClearDatabaseAsync();

            var newFirstCow = new CreateCowCommand
            {
                FarmId = Guid.NewGuid(),
                State  = CowState.Open
            };
            var newSecondCow = new CreateCowCommand
            {
                FarmId = Guid.NewGuid(),
                State  = CowState.Pregnant
            };
            var firstCow  = CowsApi.ApiV1CowsPost(newFirstCow);
            var secondCow = CowsApi.ApiV1CowsPost(newSecondCow);

            var result = CowsApi.ApiV1CowsGet();

            Assert.Equal(2, result.Count);
            Assert.Equal(firstCow.Id, result[0].Id);
            Assert.Equal(firstCow.FarmId, result[0].FarmId);
            Assert.Equal(firstCow.State, result[0].State);
            Assert.Equal(secondCow.Id, result[1].Id);
            Assert.Equal(secondCow.FarmId, result[1].FarmId);
            Assert.Equal(secondCow.State, result[1].State);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="body"></param>
        /// <returns>Cow</returns>
        public Cow ApiV1CowsPost(CreateCowCommand body)
        {
            var path = "/api/v1/cows";

            path = path.Replace("{format}", "json");

            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>();
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, FileParameter>();
            String postBody     = null;

            postBody = ApiClient.Serialize(body);                                     // http body (model) parameter

            // authentication setting, if any
            String[] authSettings = new String[] {  };

            // make the HTTP request
            IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling ApiV1CowsPost: " + response.Content, response.Content);
            }
            else if (((int)response.StatusCode) == 0)
            {
                throw new ApiException((int)response.StatusCode, "Error calling ApiV1CowsPost: " + response.ErrorMessage, response.ErrorMessage);
            }

            return((Cow)ApiClient.Deserialize(response.Content, typeof(Cow), response.Headers));
        }
示例#3
0
        public Task Put(Guid id, [FromBody] CreateCowCommand request)
        {
            var update = new UpdateCowCommand
            {
                Id     = id,
                FarmId = request.FarmId,
                State  = request.State
            };

            return(_mediator.Send(update));
        }
示例#4
0
        public void CreateCow()
        {
            var newCow = new CreateCowCommand
            {
                FarmId = Guid.NewGuid(),
                State  = CowState.Open
            };
            var cow = CowsApi.ApiV1CowsPost(newCow);

            Assert.Equal(newCow.FarmId, cow.FarmId);
            Assert.Equal(newCow.State, cow.State);
            Assert.NotEqual(Guid.Empty, cow.Id);
        }
示例#5
0
        public void GetCow()
        {
            var newCow = new CreateCowCommand
            {
                FarmId = Guid.NewGuid(),
                State  = CowState.Pregnant
            };
            var cow    = CowsApi.ApiV1CowsPost(newCow);
            var result = CowsApi.ApiV1CowsIdGet(cow.Id);

            Assert.Equal(newCow.FarmId, cow.FarmId);
            Assert.Equal(newCow.State, cow.State);
            Assert.Equal(cow.FarmId, result.FarmId);
            Assert.Equal(cow.State, result.State);
            Assert.Equal(cow.Id, result.Id);
        }
示例#6
0
        public void DeleteCow()
        {
            var newCow = new CreateCowCommand
            {
                FarmId = Guid.NewGuid(),
                State  = CowState.Inseminated
            };
            var cow    = CowsApi.ApiV1CowsPost(newCow);
            var result = CowsApi.ApiV1CowsIdGet(cow.Id);

            Assert.Equal(newCow.FarmId, cow.FarmId);
            Assert.Equal(newCow.State, cow.State);
            Assert.Equal(cow.FarmId, result.FarmId);
            Assert.Equal(cow.State, result.State);
            Assert.Equal(cow.Id, result.Id);

            CowsApi.ApiV1CowsIdDelete(cow.Id);
            result = CowsApi.ApiV1CowsIdGet(cow.Id);
            Assert.Null(result);
        }
示例#7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public void ApiV1CowsIdPut(Guid?id, CreateCowCommand body)
        {
            // verify the required parameter 'id' is set
            if (id == null)
            {
                throw new ApiException(400, "Missing required parameter 'id' when calling ApiV1CowsIdPut");
            }

            var path = "/api/v1/cows/{id}";

            path = path.Replace("{format}", "json");
            path = path.Replace("{" + "id" + "}", ApiClient.ParameterToString(id));

            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>();
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, FileParameter>();
            String postBody     = null;

            postBody = ApiClient.Serialize(body);                                     // http body (model) parameter

            // authentication setting, if any
            String[] authSettings = new String[] {  };

            // make the HTTP request
            IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings);

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling ApiV1CowsIdPut: " + response.Content, response.Content);
            }
            else if (((int)response.StatusCode) == 0)
            {
                throw new ApiException((int)response.StatusCode, "Error calling ApiV1CowsIdPut: " + response.ErrorMessage, response.ErrorMessage);
            }

            return;
        }
示例#8
0
 public Task <Cow> Post([FromBody] CreateCowCommand request)
 {
     return(_mediator.Send(request));
 }