public void Provider_should_return_all_matching_request_definitions()
        {
            var provider = new SlaProvider();

            var def1 = new SlaDefinition(
                MessageDefinition.Create <IRequestOne>(r => r.OneId),
                MessageDefinition.Create <IResponseOne>(r => r.Id),
                TimeSpan.FromSeconds(1));

            var def2 = new SlaDefinition(
                MessageDefinition.Create <IRequestTwo>(r => r.TwoId),
                MessageDefinition.Create <IResponseTwo>(r => r.Id),
                TimeSpan.FromSeconds(2));

            var def3 = new SlaDefinition(
                MessageDefinition.Create <IExtendedRequestOne>(r => r.OneId),
                MessageDefinition.Create <IResponseOne>(r => r.Id),
                TimeSpan.FromSeconds(3));

            provider.Add(def1);
            provider.Add(def2);
            provider.Add(def3);

            var definitions = provider.GetRequestDefinitions(new Mock <IExtendedRequestOne>().Object);

            Assert.That(definitions.ToArray(), Is.EquivalentTo(new[] { def1.Request, def3.Request }));
        }
示例#2
0
        public void It_should_create_definitions()
        {
            var provider = new SlaProvider();

            SlaDefinitionBuilder.For <IRequest>(x => x.RequestId)
            .AddSla <IResponse>(TimeSpan.FromSeconds(1), x => x.ResponseId)
            .AddSla <IErrorResponse>(TimeSpan.FromSeconds(2), x => x.ResponseId)
            .Configure(provider);

            Assert.That(provider.GetRequestDefinitions(new Mock <IRequest>().Object).Count(), Is.EqualTo(1), "request mapping");

            Assert.That(provider.GetSlaDefinitionsFor(new Mock <IResponse>().Object).Single().Sla, Is.EqualTo(TimeSpan.FromSeconds(1)));
            Assert.That(provider.GetSlaDefinitionsFor(new Mock <IErrorResponse>().Object).Single().Sla, Is.EqualTo(TimeSpan.FromSeconds(2)));
        }
        public void Provider_should_return_one_request_definition_if_multiple_slas_are_referring_to_the_same_request()
        {
            var provider = new SlaProvider();

            var requestDefinition = MessageDefinition.Create <IRequestOne>(r => r.OneId);

            var def1 = new SlaDefinition(
                requestDefinition,
                MessageDefinition.Create <IResponseOne>(r => r.Id),
                TimeSpan.FromSeconds(1));

            var def2 = new SlaDefinition(
                requestDefinition,
                MessageDefinition.Create <IResponseTwo>(r => r.Id),
                TimeSpan.FromSeconds(2));

            provider.Add(def1);
            provider.Add(def2);

            Assert.That(provider.GetRequestDefinitions(new Mock <IRequestOne>().Object).ToArray(), Is.EqualTo(new[] { requestDefinition }));
        }