Ejemplo n.º 1
0
        public void UpsertSucceedsWhenETagsMatch()
        {
            // Arrange
            const string ETAG1 = "ETag 001";
            const string ETAG2 = "ETag 002";

            // Record in storage
            var existingSimulation = new SimulationModel {
                Id = SIMULATION_ID
            };
            var existingRecord = new DataRecord
            {
                Id   = SIMULATION_ID,
                Data = JsonConvert.SerializeObject(existingSimulation)
            };

            existingRecord.SetETag(ETAG1);

            // Record to write
            var newSimulation = new SimulationModel
            {
                Id   = SIMULATION_ID,
                ETag = existingRecord.GetETag()
            };

            // Record after writing to storage
            var updatedRecord = new DataRecord {
                Id = SIMULATION_ID
            };

            updatedRecord.SetETag(ETAG2);

            this.simulationsStorage.Setup(x => x.GetAsync(SIMULATION_ID))
            .ReturnsAsync(existingRecord);
            this.simulationsStorage.Setup(x => x.UpsertAsync(It.IsAny <IDataRecord>(), It.IsAny <string>()))
            .ReturnsAsync(updatedRecord);

            // Act
            var result = this.target.UpsertAsync(newSimulation, false)
                         .CompleteOrTimeout().Result;

            // Assert
            Assert.Matches(ETAG2, result.ETag);
        }