コード例 #1
0
        public void context_can_get_process_data()
        {
            //arrange
            MatProcessData processData = MatProcessDataHelper.CreateProcessDataObject();
            var            bsonObject  = BsonDocument.Parse(JsonConvert.SerializeObject(processData));

            collection.InsertOne(bsonObject);
            //act
            var context = new MatDbContext(mockOptions.Object);
            var filter  = Builders <BsonDocument> .Filter.Eq("_id", processData.Id);

            var result            = context.getCollection().FindAsync(filter).Result.FirstOrDefault();
            var resultDesirialzie = BsonSerializer.Deserialize <MatProcessData>(result);

            //assert
            Assert.AreEqual(processData.Id, resultDesirialzie.Id);
            Assert.AreEqual(processData.ProcessType.value, resultDesirialzie.ProcessType.value);
            Assert.AreEqual(processData.ProcessType.name, resultDesirialzie.ProcessType.name);
            Assert.AreEqual(processData.DateCreated, resultDesirialzie.DateCreated);
            Assert.AreEqual(processData.DateLastModified, resultDesirialzie.DateLastModified);
            Assert.AreEqual(processData.DateCompleted, resultDesirialzie.DateCompleted);
            Assert.AreEqual(processData.ProcessDataAvailable, resultDesirialzie.ProcessDataAvailable);
            Assert.AreEqual(processData.ProcessDataSchemaVersion, resultDesirialzie.ProcessDataSchemaVersion);
            Assert.AreEqual(processData.ProcessStage, resultDesirialzie.ProcessStage);
            Assert.AreEqual(processData.LinkedProcessId, resultDesirialzie.LinkedProcessId);
            Assert.AreEqual(processData.PreProcessData, resultDesirialzie.PreProcessData);
            Assert.AreEqual(processData.ProcessData, resultDesirialzie.ProcessData);
            Assert.AreEqual(processData.PostProcessData, resultDesirialzie.PostProcessData);
        }
        public void update_process_controller_end_to_end_test(string processRef)
        {
            //arrange
            var dataToInsert = MatProcessDataHelper.CreateProcessDataObject();

            dataToInsert.Id = processRef;
            _dbcontext.getCollection().InsertOne(BsonDocument.Parse(JsonConvert.SerializeObject(dataToInsert)));
            //fields to update
            var dataToUpdate = new MatUpdateProcessData();

            dataToUpdate.DateLastModified = DateTime.Now;
            dataToUpdate.PreProcessData   = new
            {
                randomField = "abc"
            };
            var request = new UpdateProcessDataRequest()
            {
                processRef = processRef, processDataToUpdate = dataToUpdate
            };
            //act
            var response = _processDataController.UpdateExistingProcessDocument(request);
            var okResult = (OkObjectResult)response;
            var updateProcessDataResponse = okResult.Value as UpdateProcessDataResponse;

            //assert
            Assert.IsInstanceOf <MatProcessData>(updateProcessDataResponse.UpdatedProcessData);
            Assert.AreEqual(processRef, updateProcessDataResponse.UpdatedProcessData.Id);
            Assert.AreEqual(dataToUpdate.DateLastModified.ToShortDateString(),
                            updateProcessDataResponse.UpdatedProcessData.DateLastModified.ToShortDateString());
            Assert.AreEqual(JsonConvert.SerializeObject(dataToUpdate.PreProcessData),
                            JsonConvert.SerializeObject(updateProcessDataResponse.UpdatedProcessData.PreProcessData));
        }
コード例 #3
0
        public void test_that_object_can_be_successfully_updated()
        {
            //arrange
            MatProcessData processData = MatProcessDataHelper.CreateProcessDataObject();
            var            bsonObject  = BsonDocument.Parse(JsonConvert.SerializeObject(processData));

            collection.InsertOne(bsonObject);
            //object to update
            var objectToUpdate = new MatUpdateProcessData();
            var processRef     = processData.Id;

            objectToUpdate.DateLastModified = _faker.Date.Recent();
            objectToUpdate.ProcessData      = new
            {
                firstField  = _faker.Random.Word(),
                anyField    = _faker.Random.Words(),
                numberField = _faker.Random.Number()
            };
            //get update definition
            var updateDefinition = UpdateProcessDocumentHelper.PrepareFieldsToBeUpdated(objectToUpdate);

            //act
            var result = processDataGateway.UpdateProcessData(updateDefinition, processRef);

            //assert
            Assert.AreEqual(processRef, result.Id);
            Assert.AreEqual(JsonConvert.SerializeObject(objectToUpdate.ProcessData), JsonConvert.SerializeObject(result.ProcessData));
            Assert.AreEqual(objectToUpdate.DateLastModified.ToShortDateString(), result.DateLastModified.ToShortDateString());
            Assert.IsInstanceOf <MatProcessData>(result);
        }
コード例 #4
0
        public void test_that_gateway_return_object_matches_object_in_database()
        {
            //arrange
            MatProcessData processData = MatProcessDataHelper.CreateProcessDataObject();
            var            bsonObject  = BsonDocument.Parse(JsonConvert.SerializeObject(processData));

            collection.InsertOne(bsonObject);
            //act
            var result = processDataGateway.GetProcessData(processData.Id);

            //assert
            Assert.AreEqual(processData.Id, result.Id);
            Assert.AreEqual(processData.ProcessType.value, result.ProcessType.value);
            Assert.AreEqual(processData.ProcessType.name, result.ProcessType.name);
            Assert.AreEqual(processData.DateCreated, result.DateCreated);
            Assert.AreEqual(processData.DateLastModified, result.DateLastModified);
            Assert.AreEqual(processData.DateCompleted, result.DateCompleted);
            Assert.AreEqual(processData.ProcessDataAvailable, result.ProcessDataAvailable);
            Assert.AreEqual(processData.ProcessDataSchemaVersion, result.ProcessDataSchemaVersion);
            Assert.AreEqual(processData.ProcessStage, result.ProcessStage);
            Assert.AreEqual(processData.LinkedProcessId, result.LinkedProcessId);
            Assert.AreEqual(processData.PreProcessData, result.PreProcessData);
            Assert.AreEqual(processData.ProcessData, result.ProcessData);
            Assert.AreEqual(processData.PostProcessData, result.PostProcessData);
            Assert.IsInstanceOf <MatProcessData>(result);
        }
        public void given_a_valid_and_existing_processRef_when_GetProcessData_controller_method_is_called_then_it_returns_a_200_Ok_result()
        {
            //arrange
            int expectedStatusCode = 200;
            var existingDocument   = MatProcessDataHelper.CreateProcessDataObject();

            _dbcontext.getCollection().InsertOne(BsonDocument.Parse(JsonConvert.SerializeObject(existingDocument))); // insert expected document, which we expect the gateway to retrieve
            var request = new GetProcessDataRequest()
            {
                processRef = existingDocument.Id
            };                                                                              //valid, and existing

            //act
            var contollerResponse      = _processDataController.GetProcessData(request);
            var controllerObjectResult = contollerResponse as ObjectResult;

            //assert
            Assert.NotNull(contollerResponse);
            Assert.IsInstanceOf <OkObjectResult>(controllerObjectResult);
            Assert.AreEqual(expectedStatusCode, controllerObjectResult.StatusCode);
        }
コード例 #6
0
        public void can_create_mat_process_data_object_from_populated_object()
        {
            //arrange
            var matProcessData = MatProcessDataHelper.CreateProcessDataObject();
            //act
            var processDataFromFactory = ProcessDataFactory.CreateProcessDataObject(BsonDocument.Parse(JsonConvert.SerializeObject(matProcessData)));

            //assert
            Assert.AreEqual(matProcessData.Id, processDataFromFactory.Id);
            Assert.AreEqual(matProcessData.ProcessType.value, processDataFromFactory.ProcessType.value);
            Assert.AreEqual(matProcessData.ProcessType.name, processDataFromFactory.ProcessType.name);
            Assert.AreEqual(matProcessData.DateCreated, processDataFromFactory.DateCreated);
            Assert.AreEqual(matProcessData.DateLastModified, processDataFromFactory.DateLastModified);
            Assert.AreEqual(matProcessData.DateCompleted, processDataFromFactory.DateCompleted);
            Assert.AreEqual(matProcessData.ProcessDataAvailable, processDataFromFactory.ProcessDataAvailable);
            Assert.AreEqual(matProcessData.ProcessDataSchemaVersion, processDataFromFactory.ProcessDataSchemaVersion);
            Assert.AreEqual(matProcessData.ProcessStage, processDataFromFactory.ProcessStage);
            Assert.AreEqual(matProcessData.LinkedProcessId, processDataFromFactory.LinkedProcessId);
            Assert.AreEqual(matProcessData.PreProcessData, processDataFromFactory.PreProcessData);
            Assert.AreEqual(matProcessData.ProcessData, processDataFromFactory.ProcessData);
            Assert.AreEqual(matProcessData.PostProcessData, processDataFromFactory.PostProcessData);
        }
        public void given_a_valid_and_existing_processRef_when_GetProcessData_controller_method_is_called_then_it_returns_matching_document_from_the_database()
        {
            //arrange
            var    expectedDocument   = MatProcessDataHelper.CreateProcessDataObject();
            string expectedProcessRef = expectedDocument.Id;

            _dbcontext.getCollection().InsertOne(BsonDocument.Parse(JsonConvert.SerializeObject(expectedDocument))); // insert expected document, which we expect the gateway to retrieve

            GetProcessDataRequest request = new GetProcessDataRequest()
            {
                processRef = expectedProcessRef
            };

            //act
            var response = _processDataController.GetProcessData(request);
            var okResult = (OkObjectResult)response;
            var getProcessDataResponse = okResult.Value as GetProcessDataResponse;
            var retrievedDocument      = getProcessDataResponse.ProcessData;

            //assert
            Assert.IsInstanceOf <MatProcessData>(retrievedDocument);
            Assert.NotNull(getProcessDataResponse.ProcessData);
            Assert.NotNull(getProcessDataResponse.ProcessData.ProcessType);

            Assert.That(
                expectedProcessRef == retrievedDocument.Id &&
                expectedDocument.ProcessType.name == retrievedDocument.ProcessType.name &&
                expectedDocument.ProcessType.value == retrievedDocument.ProcessType.value &&
                expectedDocument.DateCreated == retrievedDocument.DateCreated &&
                expectedDocument.DateLastModified == retrievedDocument.DateLastModified &&
                expectedDocument.DateCompleted == retrievedDocument.DateCompleted &&
                expectedDocument.ProcessDataAvailable == retrievedDocument.ProcessDataAvailable &&
                expectedDocument.ProcessDataSchemaVersion == retrievedDocument.ProcessDataSchemaVersion &&
                expectedDocument.ProcessStage == retrievedDocument.ProcessStage &&
                expectedDocument.LinkedProcessId == retrievedDocument.LinkedProcessId
                );
        }