Beispiel #1
0
        public async Task CrushTest()
        {
            using (var context = new TrafficLightContext(ContextOptions))
            {
                SequencesController    seqController = new SequencesController(context, new SequencesService());
                ObservationsController obsController = new ObservationsController(context, new SequencesService(), new ObservationsService(context));


                string sequenceJson = await seqController.Create();

                var    addSequenceResponseType = new { status = "", response = new { sequence = "" } };
                var    addSequenceResponse     = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(sequenceJson, addSequenceResponseType);
                string getSequenceJson         = seqController.Get(addSequenceResponse.response.sequence);
                var    getSequenceResponseType = new { status = "", response = new { clock = new string[2], color = "" } };
                var    getSequenceResponse     = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(getSequenceJson, getSequenceResponseType);
                string obsJson = await obsController.Create(new ObservationRequest()
                {
                    Sequence    = addSequenceResponse.response.sequence,
                    Observation = new UserObservation()
                    {
                        Color   = getSequenceResponse.response.color,
                        Numbers = getSequenceResponse.response.clock
                    }
                });

                Assert.Equal("green", getSequenceResponse.response.color);
                var addObsResponseType = new { status = "", response = new { missing = new string[2], numbers = new int[2] } };
                var addObsResponse     = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(obsJson, addObsResponseType);
            }
        }
        public void GetTest()
        {
            using (var context = new TrafficLightContext(ContextOptions))
            {
                var controller = new SequencesController(context, new SequencesService());

                string responseJson = controller.Get(this.sequence.Id);
                var    responseType = new { status = "", response = new { clock = new string[2], color = "" } };
                var    response     = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(responseJson, responseType);
                bool   colorValid   = response.response.color == "green" || response.response.color == "red";


                Assert.True(colorValid);
                Assert.Equal("green", response.response.color);
                Assert.Equal(2, response.response.clock.Length);
                Assert.Equal("ok", response.status);
            }
        }