Пример #1
0
        public async Task Should_copy_the_property_values_from_strings()
        {
            InitializeContext <TestInitializerMessage> context = await MessageInitializerCache <TestInitializerMessage> .Initialize(new
            {
                StringValue         = _stringValue,
                BoolValue           = _boolValue.ToString(),
                ByteValue           = _byteValue.ToString(),
                ShortValue          = _shortValue.ToString(),
                IntValue            = _intValue.ToString(),
                LongValue           = _longValue.ToString(),
                DoubleValue         = _doubleValue.ToString(CultureInfo.InvariantCulture),
                DecimalValue        = _decimalValue.ToString(CultureInfo.InvariantCulture),
                DateTimeValue       = _dateTimeValue.ToString("O"),
                DateTimeOffsetValue = _dateTimeOffsetValue.ToString("O"),
                TimeSpanValue       = _timeSpanValue.ToString("c"),
                DayValue            = _dayValue.ToString(),
                ObjectValue         = _objectValue
            });

            var message = context.Message;

            Assert.That(message.StringValue, Is.EqualTo(_stringValue));
            Assert.That(message.BoolValue, Is.EqualTo(_boolValue));
            Assert.That(message.ByteValue, Is.EqualTo(_byteValue));
            Assert.That(message.ShortValue, Is.EqualTo(_shortValue));
            Assert.That(message.IntValue, Is.EqualTo(_intValue));
            Assert.That(message.LongValue, Is.EqualTo(_longValue));
            Assert.That(message.DoubleValue, Is.EqualTo(_doubleValue));
            Assert.That(message.DecimalValue, Is.EqualTo(_decimalValue));
            Assert.That(message.DateTimeValue, Is.EqualTo(_dateTimeValue));
            Assert.That(message.DateTimeOffsetValue, Is.EqualTo(_dateTimeOffsetValue));
            Assert.That(message.TimeSpanValue, Is.EqualTo(_timeSpanValue));
            Assert.That(message.DayValue, Is.EqualTo(_dayValue));
            Assert.That(message.ObjectValue, Is.EqualTo(_objectValue));
        }
Пример #2
0
        public Task Apply(InitializeContext <TMessage, TInput> context)
        {
            Task <TProperty> propertyTask = _propertyProvider.GetProperty(context);

            if (propertyTask.IsCompleted)
            {
                if (_messageProperty.TargetType == context.MessageType)
                {
                    _messageProperty.Set(context.Message, propertyTask.Result);
                }
                return(TaskUtil.Completed);
            }

            async Task ApplyAsync()
            {
                var propertyValue = await propertyTask.ConfigureAwait(false);

                if (_messageProperty.TargetType == context.MessageType)
                {
                    _messageProperty.Set(context.Message, propertyValue);
                }
            }

            return(ApplyAsync());
        }
Пример #3
0
 public Task <TProperty> GetProperty <T>(InitializeContext <T, TInput> context)
     where T : class
 {
     return(context.HasInput && _converter.TryConvert(_inputProperty.Get(context.Input), out var result)
         ? Task.FromResult(result)
         : TaskUtil.Default <TProperty>());
 }
Пример #4
0
        protected async Task <T> Init <TData, T>(ConsumeEventContext <FutureState, TData> context, object values = default)
            where TData : class
            where T : class
        {
            InitializeContext <T> initializeContext = await MessageInitializerCache <T> .Initialize(context.Data, context.CancellationToken);

            initializeContext = await MessageInitializerCache <T> .Initialize(initializeContext, new
            {
                context.Instance.Canceled,
                context.Instance.Completed,
                context.Instance.Created,
                context.Instance.Deadline,
                context.Instance.Faulted,
                context.Instance.Location,
            });

            var request = context.Instance.GetRequest <TRequest>();

            if (request != null)
            {
                initializeContext = await MessageInitializerCache <T> .Initialize(initializeContext, request);
            }

            if (values != null)
            {
                initializeContext = await MessageInitializerCache <T> .Initialize(initializeContext, values);
            }

            return(initializeContext.Message);
        }
Пример #5
0
        Task IFilter <ConsumeContext <T> > .Send(ConsumeContext <T> context, IPipe <ConsumeContext <T> > next)
        {
            var transformContext = new ConsumeTransformContext <T>(context, context.Message);

            Task <InitializeContext <T> > initializeTask = _initializer.Initialize(_initializer.Create(transformContext), context.Message);

            if (initializeTask.IsCompleted)
            {
                var message = initializeTask.Result.Message;

                return(next.Send(ReferenceEquals(message, context.Message)
                    ? context
                    : new MessageConsumeContext <T>(context, message)));
            }

            async Task SendAsync()
            {
                InitializeContext <T> initializeContext = await initializeTask.ConfigureAwait(false);

                await next.Send(ReferenceEquals(initializeContext.Message, context.Message)
                                ?context
                                : new MessageConsumeContext <T>(context, initializeContext.Message)).ConfigureAwait(false);
            }

            return(SendAsync());
        }
Пример #6
0
        public async Task GetAddressByIdAsync_WithValidId_ShouldReturnCorrectAddress()
        {
            //Arrange
            var context = InitializeContext.CreateContextForInMemory();

            addressesService = new AddressesService(context);

            var addressId = 1;

            var testAddress = new Address
            {
                Id           = 1,
                City         = "Sofia",
                Country      = "Bulgaria",
                CreatedOn    = DateTime.UtcNow,
                EmailAddress = "*****@*****.**",
                District     = "Student City",
                ZipCode      = 1000,
                PhoneNumber  = "08552332",
                Street       = "Ivan Vazov"
            };

            await context.Addresses.AddAsync(testAddress);

            await context.SaveChangesAsync();

            //Act
            var result = await addressesService.GetAddressByIdAsync(addressId);

            //Assert
            Assert.Equal(result, testAddress);
        }
Пример #7
0
 public Task <TProperty> Convert <T>(InitializeContext <T, TInput> context, object propertyValue)
     where T : class
 {
     return(_converter == null
         ? TaskUtil.Default <TProperty>()
         : _converter.Convert(context, (TObject)propertyValue));
 }
 public Task <Task <TProperty> > GetProperty <T>(InitializeContext <T, TInput> context)
     where T : class
 {
     return(Task.FromResult(context.HasInput
         ? _provider.GetProperty(context)
         : TaskUtil.Default <TProperty>()));
 }
        Task <TProperty> IPropertyConverter <TProperty, TProperty> .Convert <TMessage>(InitializeContext <TMessage> context, TProperty input)
        {
            if (input == null || !context.TryGetPayload(out TransformContext <TMessage> transformContext) || !transformContext.HasInput)
            {
                return(TaskUtil.Default <TProperty>());
            }

            var propertyTransformContext = new PropertyTransformContext <TMessage, TProperty>(transformContext, input);

            InitializeContext <TProperty> messageContext = _initializer.Create(propertyTransformContext);

            Task <InitializeContext <TProperty> > initTask = _initializer.Initialize(messageContext, input);

            if (initTask.IsCompleted)
            {
                return(Task.FromResult(initTask.Result.Message));
            }

            async Task <TProperty> ConvertAsync()
            {
                InitializeContext <TProperty> result = await initTask.ConfigureAwait(false);

                return(result.Message);
            }

            return(ConvertAsync());
        }
Пример #10
0
 public InitializerSendContextPipe(IHeaderInitializer <TMessage, TInput>[] initializers, InitializeContext <TMessage, TInput> context,
                                   IPipe <SendContext> pipe)
 {
     _initializers = initializers;
     _sendPipe     = pipe;
     _context      = context;
 }
Пример #11
0
        public async Task CreateInspect_WithValidInput_ShouldBeCorrect()
        {
            MapperInitializer.InitializeMapper();
            var context         = InitializeContext.CreateContextForInMemory();
            var repository      = new EfDeletableEntityRepository <Inspect>(context);
            var inspectsService = new InspectsService(repository);

            var userId           = "U1";
            var inspectTypeId    = "I1";
            var liftId           = "L1";
            var notes            = "test";
            var prescriptions    = "presTest";
            var supportCompanyId = "S1";

            await inspectsService.CreateAsync(userId, inspectTypeId, liftId, notes, prescriptions, supportCompanyId);

            var inspect = context.Inspects.FirstOrDefaultAsync().Result;

            Assert.Equal(userId, inspect.ApplicationUserId);
            Assert.Equal(inspectTypeId, inspect.InspectTypeId);
            Assert.Equal(liftId, inspect.LiftId);
            Assert.Equal(notes, inspect.Notes);
            Assert.Equal(prescriptions, inspect.Prescriptions);
            Assert.Equal(supportCompanyId, inspect.SupportCompanyId);
        }
Пример #12
0
        public async Task Execute(BehaviorContext <TInstance, TData> context, Behavior <TInstance, TData> next)
        {
            ConsumeEventContext <TInstance, TData> consumeContext = context.CreateConsumeContext();

            var payload = context.Data as Fault;

            InitializeContext <RequestFaulted <TRequest> > initializeContext = await MessageInitializerCache <RequestFaulted <TRequest> > .Initialize(new
            {
                context.Instance.CorrelationId,
                PayloadType = TypeMetadataCache <Fault <TRequest> > .MessageTypeNames,
                Payload     = new
                {
                    payload.FaultId,
                    payload.FaultedMessageId,
                    payload.Timestamp,
                    payload.Host,
                    payload.Exceptions
                }
            }).ConfigureAwait(false);

            object message = initializeContext.Message;

            await consumeContext.Publish(message, typeof(RequestFaulted)).ConfigureAwait(false);

            await next.Execute(context).ConfigureAwait(false);
        }
Пример #13
0
        public async Task GetMessageDetailsViewModelsAsync_WithCurrentUserNotParticipantInConversation_ShouldThrowAnInvalidOperationException()
        {
            //Arrange
            var expectedErrorMessage = "You are not participant in this conversation!";

            var moqAdsService   = new Mock <IAdsService>();
            var moqUsersService = new Mock <IUsersService>();

            moqUsersService.Setup(x => x.GetCurrentUserId())
            .Returns("FakeUserId");
            var moqIMapper = new Mock <IMapper>();
            var context    = InitializeContext.CreateContextForInMemory();

            var testingAd = CreateTestingAd();
            await context.AddAsync(testingAd);

            await context.SaveChangesAsync();

            messagesService = new MessagesService(context, moqAdsService.Object, moqUsersService.Object, moqIMapper.Object);

            //Act and assert
            var ex = await Assert.ThrowsAsync <InvalidOperationException>(() =>
                                                                          messagesService.GetMessageDetailsViewModelsAsync(1, "SenderId", "RecipientId"));

            Assert.Equal(expectedErrorMessage, ex.Message);
        }
        Task <TProperty> IPropertyConverter <TProperty, TInput> .Convert <TMessage>(InitializeContext <TMessage> context, TInput input)
        {
            if (input == null)
            {
                return(TaskUtil.Default <TProperty>());
            }

            InitializeContext <TProperty> messageContext = MessageFactoryCache <TProperty> .Factory.Create(context);

            IMessageInitializer <TProperty> initializer = typeof(TInput) == typeof(object)
                ? MessageInitializerCache <TProperty> .GetInitializer(input.GetType())
                : MessageInitializerCache <TProperty> .GetInitializer(typeof(TInput));

            Task <InitializeContext <TProperty> > initTask = initializer.Initialize(messageContext, input);

            if (initTask.IsCompleted)
            {
                return(Task.FromResult(initTask.Result.Message));
            }

            async Task <TProperty> ConvertAsync()
            {
                InitializeContext <TProperty> result = await initTask.ConfigureAwait(false);

                return(result.Message);
            }

            return(ConvertAsync());
        }
Пример #15
0
        public async Task Should_work_with_a_list()
        {
            var dto = new
            {
                Id         = 32,
                CustomerId = "CustomerXp",
                Product    = new
                {
                    Name     = "Foo",
                    Category = "Bar"
                },
                Orders = new[]
                {
                    new
                    {
                        Id      = Guid.NewGuid(),
                        Product = new
                        {
                            Name     = "Product",
                            Category = "Category"
                        },
                        Quantity = 10,
                        Price    = 10.0m
                    }
                }
            };

            var expando = JsonConvert.DeserializeObject <ExpandoObject>(JsonConvert.SerializeObject(dto));

            InitializeContext <MessageContract> message =
                await MessageInitializerCache <MessageContract> .Initialize(expando); // doesn't work (orders not included)

            Assert.That(message.Message.Id, Is.EqualTo(32));
            Assert.That(message.Message.Orders, Is.Not.Null);
        }
Пример #16
0
        public async Task GetAdministrationIndexStatisticViewModel_WithValidData_ShouldReturnCorrectResult()
        {
            //Assert
            var expectedActiveAdsCount = 10;
            var expectedAllUsersCount  = 5;

            var moqAdsService = new Mock <IAdsService>();

            moqAdsService.Setup(x => x.GetAllActiveAdsCountAsync())
            .ReturnsAsync(10);
            var moqUsersService = new Mock <IUsersService>();

            moqUsersService.Setup(x => x.GetCountOfAllUsersAsync())
            .ReturnsAsync(5);
            var moqPromotionsService = new Mock <IPromotionsService>();

            var context = InitializeContext.CreateContextForInMemory();

            statisticsService = new StatisticsService(context, moqAdsService.Object, moqUsersService.Object, moqPromotionsService.Object);

            //Act
            var actual = await statisticsService.GetAdministrationIndexStatisticViewModel();

            //Assert
            Assert.Equal(expectedActiveAdsCount, actual.AllAdsCount);
            Assert.Equal(expectedAllUsersCount, actual.AllUsersCount);
        }
Пример #17
0
        public async Task Should_properly_handle_the_big_dto()
        {
            var order = new OrderDto();

            order.Amount              = 123.45m;
            order.Id                  = 27;
            order.CustomerId          = "FRANK01";
            order.ItemType            = "Crayon";
            order.OrderState          = new OrderState(OrderStatus.Validated);
            order.TokenizedCreditCard = new TokenizedCreditCardDto
            {
                ExpirationMonth = "12",
                ExpirationYear  = "2019",
                PublicKey       = new JObject(new JProperty("key", "12345")),
                Token           = new JObject(new JProperty("value", "Token123"))
            };

            var correlationId = Guid.NewGuid();
            InitializeContext <IPaymentGatewaySubmittedEvent> message = await MessageInitializerCache <IPaymentGatewaySubmittedEvent> .Initialize(new
            {
                order,
                correlationId,
                TimeStamp         = DateTime.Now,
                ConsumerProcessed = true
            });

            Assert.That(message.Message.CorrelationId, Is.EqualTo(correlationId));
            Assert.That(message.Message.Order, Is.Not.Null);
            Assert.That(message.Message.Order.OrderState, Is.Not.Null);
            Assert.That(message.Message.Order.OrderState.Status, Is.EqualTo(OrderStatus.Validated));
            Assert.That(message.Message.Order.TokenizedCreditCard, Is.Not.Null);
            Assert.That(message.Message.Order.TokenizedCreditCard.ExpirationMonth, Is.EqualTo("12"));
        }
        public override void Initialize(InitializeContext context)
        {
            cacheManagerViewModel = (CacheManagerSectionViewModel)ContainingSection;
            backingStoreReferenceConverter = new BackingStoreReferenceConverter(cacheManagerViewModel.NullBackingStoreName);

            base.Initialize(context);
        }
Пример #19
0
        Task <TProperty> IPropertyProvider <TInput, TProperty> .GetProperty <T>(InitializeContext <T, TInput> context)
        {
            if (!context.HasInput)
            {
                return(TaskUtil.Default <TProperty>());
            }

            Task <Task <TProperty> > propertyTask = _provider.GetProperty(context);

            if (propertyTask.IsCompleted)
            {
                Task <TProperty> valueTask = propertyTask.Result;
                if (valueTask.IsCompleted)
                {
                    return(valueTask);
                }
            }

            async Task <TProperty> GetPropertyAsync()
            {
                Task <TProperty> valueTask = await propertyTask.ConfigureAwait(false);

                return(await valueTask.ConfigureAwait(false));
            }

            return(GetPropertyAsync());
        }
Пример #20
0
 public Task <MessageData <Stream> > Convert <T>(InitializeContext <T> context, Stream input)
     where T : class
 {
     return(input == null
         ? TaskUtil.Default <MessageData <Stream> >()
         : Task.FromResult <MessageData <Stream> >(new PutMessageData <Stream>(input)));
 }
Пример #21
0
        public async Task UnblockUserByIdAsync_WithValidDAta_ShouldReturnTrue()
        {
            //Arrange
            var moqHttpContext = new Mock <IHttpContextAccessor>();
            var userStore      = new Mock <IUserStore <SellMeUser> >();
            var userManager    = new Mock <UserManager <SellMeUser> >(userStore.Object, null, null, null, null, null, null, null, null);
            var context        = InitializeContext.CreateContextForInMemory();

            this.usersService = new UsersService(context, moqHttpContext.Object, userManager.Object);

            var testingUser = new SellMeUser
            {
                Id             = "UserId",
                UserName       = "******",
                IsDeleted      = true,
                EmailConfirmed = true,
                CreatedOn      = DateTime.UtcNow.AddDays(-25),
                Ads            = new List <Ad> {
                    new Ad(), new Ad()
                }
            };

            await context.SellMeUsers.AddAsync(testingUser);

            await context.SaveChangesAsync();

            //Act
            var actual = await this.usersService.UnblockUserByIdAsync("UserId");

            //Assert
            Assert.True(actual);
            Assert.False(testingUser.IsDeleted);
        }
Пример #22
0
        public Task <TProperty> GetProperty <T>(InitializeContext <T, TInput> context)
            where T : class
        {
            if (!context.TryGetPayload <TransformContext <TInput> >(out TransformContext <TInput> transformContext))
            {
                return(TaskUtil.Default <TProperty>());
            }

            if (!context.HasInput)
            {
                return(TaskUtil.Default <TProperty>());
            }

            Task <TProperty> inputTask = _inputProvider.GetProperty(context);

            if (inputTask.IsCompleted)
            {
                var propertyContext = new MessageTransformPropertyContext <TProperty, TInput>(transformContext, inputTask.Result);

                return(_valueProvider(propertyContext));
            }

            async Task <TProperty> GetPropertyAsync()
            {
                var inputValue = await inputTask.ConfigureAwait(false);

                var propertyContext = new MessageTransformPropertyContext <TProperty, TInput>(transformContext, inputValue);

                return(await _valueProvider(propertyContext).ConfigureAwait(false));
            }

            return(GetPropertyAsync());
        }
Пример #23
0
        public async Task GetUserByIdAsync_WithValidDAta_ShouldReturnCorrectUser()
        {
            //Arrange
            var expectedUserId   = "UserId";
            var expectedUsername = "******";

            var moqHttpContext = new Mock <IHttpContextAccessor>();
            var userStore      = new Mock <IUserStore <SellMeUser> >();
            var userManager    = new Mock <UserManager <SellMeUser> >(userStore.Object, null, null, null, null, null, null, null, null);

            userManager.Setup(x => x.FindByIdAsync("UserId"))
            .ReturnsAsync(new SellMeUser {
                Id = "UserId", UserName = "******"
            });

            var context = InitializeContext.CreateContextForInMemory();

            this.usersService = new UsersService(context, moqHttpContext.Object, userManager.Object);

            var testingUser = new SellMeUser {
                Id = "UserId", UserName = "******"
            };

            await context.SellMeUsers.AddAsync(testingUser);

            await context.SaveChangesAsync();

            //Act
            var actual = await this.usersService.GetUserByIdAsync("UserId");

            //Assert
            Assert.Equal(expectedUserId, actual.Id);
            Assert.Equal(expectedUsername, actual.UserName);
        }
Пример #24
0
        Task <TProperty> IPropertyConverter <TProperty, TProperty> .Convert <TMessage>(InitializeContext <TMessage> context, TProperty input)
        {
            if (input == null)
            {
                return(TaskUtil.Default <TProperty>());
            }

            InitializeContext <TProperty> messageContext = MessageFactoryCache <TProperty> .Factory.Create(context);

            Task <InitializeContext <TProperty> > initTask = _initializer.Initialize(messageContext, input);

            if (initTask.IsCompleted)
            {
                return(Task.FromResult(initTask.Result.Message));
            }

            async Task <TProperty> ConvertAsync()
            {
                InitializeContext <TProperty> result = await initTask.ConfigureAwait(false);

                return(result.Message);
            }

            return(ConvertAsync());
        }
Пример #25
0
 public Task <MessageData <byte[]> > Convert <T>(InitializeContext <T> context, MessageData <byte[]> input)
     where T : class
 {
     return(input != null
         ? Task.FromResult(input)
         : TaskUtil.Default <MessageData <byte[]> >());
 }
Пример #26
0
 public InitializerPublishContextPipe(IHeaderInitializer <TMessage, TInput>[] initializers, InitializeContext <TMessage, TInput> context,
                                      IPipe <PublishContext <TMessage> > pipe)
 {
     _initializers = initializers;
     _pipe         = pipe;
     _context      = context;
 }
Пример #27
0
        public async Task Should_copy_the_property_values_from_nullable_types()
        {
            InitializeContext <TestInitializerMessage> context = await MessageInitializerCache <TestInitializerMessage> .Initialize(new
            {
                StringValue         = _stringValue,
                BoolValue           = (bool?)_boolValue,
                ByteValue           = (byte?)_byteValue,
                ShortValue          = (short?)_shortValue,
                IntValue            = (int?)_intValue,
                LongValue           = (long?)_longValue,
                DoubleValue         = (double?)_doubleValue,
                DecimalValue        = (decimal?)_decimalValue,
                DateTimeValue       = (DateTime?)_dateTimeValue,
                DateTimeOffsetValue = (DateTimeOffset?)_dateTimeOffsetValue,
                TimeSpanValue       = (TimeSpan?)_timeSpanValue,
                DayValue            = (Day?)_dayValue
            });

            var message = context.Message;

            Assert.That(message.StringValue, Is.EqualTo(_stringValue));
            Assert.That(message.BoolValue, Is.EqualTo(_boolValue));
            Assert.That(message.ByteValue, Is.EqualTo(_byteValue));
            Assert.That(message.ShortValue, Is.EqualTo(_shortValue));
            Assert.That(message.IntValue, Is.EqualTo(_intValue));
            Assert.That(message.LongValue, Is.EqualTo(_longValue));
            Assert.That(message.DoubleValue, Is.EqualTo(_doubleValue));
            Assert.That(message.DecimalValue, Is.EqualTo(_decimalValue));
            Assert.That(message.DateTimeValue, Is.EqualTo(_dateTimeValue));
            Assert.That(message.DateTimeOffsetValue, Is.EqualTo(_dateTimeOffsetValue));
            Assert.That(message.TimeSpanValue, Is.EqualTo(_timeSpanValue));
            Assert.That(message.DayValue, Is.EqualTo(_dayValue));
        }
        public override void Initialize(InitializeContext context)
        {
            cacheManagerViewModel          = (CacheManagerSectionViewModel)ContainingSection;
            backingStoreReferenceConverter = new BackingStoreReferenceConverter(cacheManagerViewModel.NullBackingStoreName);

            base.Initialize(context);
        }
Пример #29
0
        Task IFilter <ExecuteContext <T> > .Send(ExecuteContext <T> context, IPipe <ExecuteContext <T> > next)
        {
            var transformContext = new ConsumeTransformContext <T>(context, context.Arguments);

            Task <InitializeContext <T> > initializeTask = _initializer.Initialize(_initializer.Create(transformContext), context.Arguments);

            if (initializeTask.IsCompleted)
            {
                var arguments = initializeTask.Result.Message;

                return(next.Send(ReferenceEquals(arguments, context.Arguments)
                    ? context
                    : new ExecuteContextProxy <T>(context, arguments)));
            }

            async Task SendAsync()
            {
                InitializeContext <T> initializeContext = await initializeTask.ConfigureAwait(false);

                await next.Send(ReferenceEquals(initializeContext.Message, context.Arguments)
                                ?context
                                : new ExecuteContextProxy <T>(context, initializeContext.Message)).ConfigureAwait(false);
            }

            return(SendAsync());
        }
Пример #30
0
        public Task <TProperty> GetProperty <T>(InitializeContext <T, TInput> context)
            where T : class
        {
            Task <object> propertyTask = _provider.GetProperty(context);

            if (propertyTask.IsCompleted)
            {
                var propertyValue = propertyTask.Result;
                if (propertyValue == default)
                {
                    return(TaskUtil.Default <TProperty>());
                }

                var converter = _converters.GetOrAdd(propertyValue.GetType(), CreateConverter);

                return(converter.Convert(context, propertyValue));
            }

            async Task <TProperty> GetPropertyAsync()
            {
                var propertyValue = await propertyTask.ConfigureAwait(false);

                var converter = _converters.GetOrAdd(propertyValue.GetType(), CreateConverter);

                return(await converter.Convert(context, propertyValue).ConfigureAwait(false));
            }

            return(GetPropertyAsync());
        }
Пример #31
0
        public async Task GetAddressByIdAsync_WithInvalidId_ShouldThrowArgumentException(int addressId)
        {
            //Arrange
            var context = InitializeContext.CreateContextForInMemory();

            addressesService = new AddressesService(context);
            var testAddress = new Address
            {
                Id           = 1,
                City         = "Sofia",
                Country      = "Bulgaria",
                CreatedOn    = DateTime.UtcNow,
                EmailAddress = "*****@*****.**",
                District     = "Student City",
                ZipCode      = 1000,
                PhoneNumber  = "08552332",
                Street       = "Ivan Vazov"
            };

            await context.Addresses.AddAsync(testAddress);

            await context.SaveChangesAsync();

            var expectErrorMessage = "Address with the given ID doesn't exist!";

            //Act

            var ex = await Assert.ThrowsAsync <ArgumentException>(() => addressesService.GetAddressByIdAsync(addressId));

            Assert.Equal(expectErrorMessage, ex.Message);
        }
        public override void Initialize(InitializeContext context)
        {
            var categoryElement = Subject.AncestorElements().Where(x => typeof(TraceSourceData).IsAssignableFrom(x.ConfigurationType)).First();
            categoryOverridesProperty = categoryElement.Properties.OfType<EnvironmentOverriddenElementProperty>().Where(x => x.Environment == this.Environment).First();

            categoryOverridesProperty.PropertyChanged += CategoryOverridesPropertyChanged;
            SetValue(categoryOverridesProperty.Value);
        }
        public override void Initialize(InitializeContext context)
        {
            base.Initialize(context);

            typeNameProperty = this.Property("TypeName");
            typeNameProperty.PropertyChanged += registrationTypeDependentPropertyChangedHandler;

            mapToNameProperty = this.Property("MapToName");
            mapToNameProperty.PropertyChanged += registrationTypeDependentPropertyChangedHandler;
        }
        public override void Initialize(InitializeContext context)
        {
            base.Initialize(context);

            var memoryBackingStores = cacheManagerSettings.BackingStores.Where(x => x.GetType() == typeof(CacheStorageData)).Select(x => x.Name);
            
            if (memoryBackingStores.Any())
            {
                NullBackingStoreName = memoryBackingStores.First();
            }
        }
        public override void Initialize(InitializeContext context)
        {
            base.Initialize(context);

            IElementChangeScope aliasElementChangeScope = lookup.CreateChangeScope(x =>
                                                    typeof(NamespaceElement).IsAssignableFrom(x.ConfigurationType) ||
                                                    typeof(SectionExtensionElement).IsAssignableFrom(x.ConfigurationType) ||
                                                    typeof(AliasElement).IsAssignableFrom(x.ConfigurationType) ||
                                                    typeof(AssemblyElement).IsAssignableFrom(x.ConfigurationType));

            watchAliasElementPropertyChanges = new WatchPropertyChangesWithinChangeScope(aliasElementChangeScope, SignalRegistrationTypeChanges);
        }
        public override void Initialize(InitializeContext context)
        {
            var sourceElement = this.ConfigurationElement as ManageableConfigurationSourceElement;
            if (sourceElement != null)
            {
                sourceElement.ConfigurationManageabilityProviders.Clear();

                var retriever = new ConfigurationManageabilityProviderAttributeRetriever(this.assemblyLocator);
                foreach (var sectionProviderElement in GetConfigurationManageabilityProviders(retriever))
                {
                    sourceElement.ConfigurationManageabilityProviders.Add(sectionProviderElement);
                }
            }
        }
        public override void Initialize(InitializeContext context)
        {
            Guard.ArgumentNotNull(context, "context");

            if (context.WasLoadedFromSource)
            {
                InitializeSubordinateSectionViewModels(
                    (DatabaseSettings)context.LoadSource.GetLocalSection(DatabaseSettings.SectionName),
                    (OracleConnectionSettings)context.LoadSource.GetLocalSection(OracleConnectionSettings.SectionName));
            }
            else
            {
                InitializeSubordinateSectionViewModels(null, null);
            }

        }