public async Task UndeleteItemAsync_Auth_FormulatesCorrectResponse_WithPrecondition()
        {
            // Arrange
            MockHandler.AddResponse(HttpStatusCode.OK, payload);
            var obj = new IdEntity {
                Id = sId, Version = "etag"
            };

            // Act
            await authTable.UndeleteItemAsync(obj).ConfigureAwait(false);

            // Assert
            var request = AssertSingleRequest(ServiceRequest.PATCH, expectedEndpoint);

            Assert.Equal("{\"deleted\":false}", await request.Content.ReadAsStringAsync());
            AssertEx.HasHeader(request.Headers, "X-ZUMO-AUTH", ValidAuthenticationToken.Token);
            AssertEx.HasHeader(request.Headers, "If-Match", "\"etag\"");
            Assert.Equal(payload, obj);
        }
Example #2
0
        /// <summary>
        /// Creates a paging response with JObjects.
        /// </summary>
        /// <param name="count"></param>
        /// <param name="totalCount"></param>
        /// <param name="nextLink"></param>
        /// <returns></returns>
        private Page <JObject> CreatePageOfJsonItems(int count, long?totalCount = null, Uri nextLink = null)
        {
            List <JObject>  items    = new();
            List <IdEntity> entities = new();

            for (int i = 0; i < count; i++)
            {
                var entity = new IdEntity {
                    Id = Guid.NewGuid().ToString("N"), StringValue = $"Item #{i}"
                };
                items.Add(CreateJsonDocument(entity));
                entities.Add(entity);
            }
            MockHandler.AddResponse(HttpStatusCode.OK, new Page <IdEntity> {
                Items = entities, Count = totalCount, NextLink = nextLink
            });
            return(new Page <JObject> {
                Items = items, Count = totalCount, NextLink = nextLink
            });
        }
Example #3
0
        public HttpResponseMessage byId([FromBody] IdEntity entity)
        {
            int id = 0;

            if (entity != null)
            {
                id = entity.Id;
            }

            var formato = _formatoServices.GetFormatoById(id);

            if (formato != null && formato[0].Equals("0000"))
            {
                FormatoEntity formatoEnt = (FormatoEntity)formato.ElementAt(1);
                formato = _formatoServices.setDescripcion(formatoEnt);

                return(Request.CreateResponse(HttpStatusCode.OK, formato));
            }
            return(Request.CreateResponse(HttpStatusCode.NotFound, formato));
        }
Example #4
0
        public async Task <int> GetNextTableId(CloudTable table)
        {
            // Get current Id
            var selectOperation = TableOperation.Retrieve <IdEntity>("1", "KEY");
            var result          = await table.ExecuteAsync(selectOperation);

            if (!(result.Result is IdEntity entity))
            {
                entity = new IdEntity
                {
                    PartitionKey = "1",
                    RowKey       = "KEY",
                    Id           = 1024
                };
            }
            entity.Id++;

            // Update
            var updateOperation = TableOperation.InsertOrMerge(entity);
            await table.ExecuteAsync(updateOperation);

            return(entity.Id);
        }
        public async Task DeleteItemAsync_FormulatesCorrectResponse(bool hasPrecondition)
        {
            // Arrange
            MockHandler.AddResponse(HttpStatusCode.NoContent);
            var item = new IdEntity {
                Id = sId, Version = hasPrecondition ? "etag" : null
            };

            // Act
            await table.DeleteItemAsync(item).ConfigureAwait(false);

            // Assert
            var request = AssertSingleRequest(HttpMethod.Delete, expectedEndpoint);

            if (hasPrecondition)
            {
                AssertEx.HasHeader(request.Headers, "If-Match", "\"etag\"");
            }
            else
            {
                Assert.False(request.Headers.Contains("If-Match"));
            }
        }
Example #6
0
        public async Task AddErrorAsync_CreatesErrorFromOperation_NullResult_WithStatus()
        {
            var batch = await CreateBatch();

            var op   = new InsertOperation("movies", Guid.NewGuid().ToString());
            var item = new IdEntity {
                Id = Guid.NewGuid().ToString(), StringValue = "test"
            };
            var obj = JObject.FromObject(item);

            await batch.AddErrorAsync(op, HttpStatusCode.BadRequest, null, obj);

            Assert.Single(store.TableMap[SystemTables.SyncErrors]);
            var error = store.TableMap[SystemTables.SyncErrors].Values.First();

            Assert.NotEmpty(error.Value <string>("id"));
            Assert.Equal(400, error.Value <int?>("status"));
            Assert.Equal("movies", error.Value <string>("tableName"));
            Assert.Equal(1, error.Value <int>("version"));
            Assert.Equal(2, error.Value <int>("kind"));
            Assert.Null(error.Value <string>("item"));
            Assert.Null(error.Value <string>("rawResult"));
        }
Example #7
0
        public HttpResponseMessage editarFormato([FromBody] IdEntity entity)
        {
            int id = 0;

            if (entity != null)
            {
                id = entity.Id;
            }

            //Formato a editar
            var formatoEditar = _formatoServices.GetFormatoById(id);
            //Normatividad Padre
            var normas = _normaServices.GetNormasPadre();
            //Tipo Formato
            var tipoFormato = _tablaServices.GetParametrosVert(TIPOFORMATO);
            //Tipo periodicidad
            var tipoPeriodicidad = _periodicidadServices.GetAllPeriodicidades();
            //Tipo plazo
            var tipoPlazo = _plazoServices.GetAllPlazos();
            //Lista Sección
            var seccionList = _tablaServices.GetParametrosVert(SECCION);
            //Lista estado
            var estadoList = _tablaServices.GetParametrosVert(ESTADO);

            if (formatoEditar != null && normas != null && tipoFormato != null && tipoPeriodicidad != null && tipoPlazo != null && seccionList != null && estadoList != null)
            {
                //var normaEntities = normas as List<NormaPadreEntity> ?? normas.ToList();
                //var sectorServicioEntities = sectorList as List<SectorServicioEntity> ?? sectorList.ToList();
                //var entidadEntities = entidadList as List<EntidadEntity> ?? entidadList.ToList();

                object[] jsonArray = { formatoEditar, normas, tipoFormato, tipoPeriodicidad, tipoPlazo, seccionList, estadoList };

                return(Request.CreateResponse(HttpStatusCode.OK, jsonArray));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No norma found for this id"));
        }