Ejemplo n.º 1
0
 public void CanGenerateUniqueIdentifier()
 {
     var factory = new GuidFactory();
     var value1 = factory.Generate();
     var value2 = factory.Generate();
     Assert.NotEqual(value1,value2);
 }
Ejemplo n.º 2
0
        public void CreateMd5_RfcExample_EncodesAsExpected()
        {
            // See https://www.rfc-editor.org/errata/eid1352
            var guid = GuidFactory.CreateMd5(GuidNamespaces.Dns,
                                             new UTF8Encoding(encoderShouldEmitUTF8Identifier: false).GetBytes("www.widgets.com"));

            Assert.Equal("3d813cbb-47fb-32ba-91df-831e1593ac29", guid.ToString("D"));
        }
Ejemplo n.º 3
0
        public void CreateMd5_PythonExample_EncodesAsExpected()
        {
            // See https://docs.python.org/3/library/uuid.html#example
            var guid = GuidFactory.CreateMd5(GuidNamespaces.Dns,
                                             new UTF8Encoding(encoderShouldEmitUTF8Identifier: false).GetBytes("python.org"));

            Assert.Equal("6fa459ea-ee8a-3ca4-894e-db77e160355e", guid.ToString("D"));
        }
Ejemplo n.º 4
0
        public void CreateSha1_PythonExample_EncodesAsExpected()
        {
            // See https://docs.python.org/3/library/uuid.html#example
            var guid = GuidFactory.CreateSha1(GuidNamespaces.Dns,
                                              new UTF8Encoding(encoderShouldEmitUTF8Identifier: false).GetBytes("python.org"));

            Assert.Equal("886313e1-3b8a-5372-9b90-0c9aee199e5d", guid.ToString("D"));
        }
Ejemplo n.º 5
0
        public void Decode_LittleEndianByteArray_Roundtrip()
        {
            var bytes   = new byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
            var guid    = GuidFactory.FromLittleEndianByteArray(bytes);
            var decoded = guid.Decode();

            Assert.Equal(bytes, decoded.ToLittleEndianByteArray());
        }
Ejemplo n.º 6
0
 public void SetUpTest()
 {
     GuidFactory.SetStrategy(() =>
     {
         var result = Guid.NewGuid();
         GeneratedGuids.Add(result);
         return(result);
     });
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Messages are enqueued and delivered after the current message have been processed.
        /// </summary>
        /// <param name="message">message to send</param>
        /// <returns>task</returns>
        public Task SendAsync(Message message)
        {
            if (message.MessageId == Guid.Empty)
            {
                message.MessageId = GuidFactory.Create();
            }

            _outboundMessages.Add(message);
            return(Task.FromResult <object>(null));
        }
Ejemplo n.º 8
0
        public Account(string businessName, int accountNumber, Guid?newAccountId) : this()
        {
            var accountId = newAccountId ?? GuidFactory.NewGuidComb();

            ApplyChange(new AccountCreated(accountId, businessName, accountNumber));

            AddSystemTag("Transportation", true, false);
            AddSystemTag("Sick Leave", false, true);
            AddSystemTag("Training", true, true);
        }
Ejemplo n.º 9
0
        public static async Task <bool> Custodian(FbConnection fbConnection, EcfTableReader ecfTableReader, int tenantId)
        {
            Guid guidExtern = GuidFactory.Create(GuidFactory.DnsNamespace, ecfTableReader.GetValue <string>("Id"));
            var  success    = 0;
            var  sql        =
                "INSERT INTO \"Sorgeberechtigte\" " +
                "(" +
                "  \"Mandant\", \"GUIDExtern\", \"Nachname\", \"Vorname\", \"Anrede\", " +
                "  \"Strasse\", \"Land\", \"PLZ\", \"Ort\", \"Email\", \"TelefonPrivat\", \"TelefonBeruf\", " +
                "  \"Status2\" " +
                ") " +
                "VALUES ( " +
                "  @TenantId, @GUIDExtern, @LastName, @FirstName, @Salutation, " +
                "  @AddressLines, @Country, @PostalCode, @Locality, @Email, @HomePhoneNumber, @OfficePhoneNumber, " +
                "  @Status2 " +
                ")";


            using var fbTransaction = fbConnection.BeginTransaction();
            try
            {
                using var fbCommand = new FbCommand(sql, fbConnection, fbTransaction);

                Helper.SetParamValue(fbCommand, "@TenantId", FbDbType.Integer, tenantId);
                Helper.SetParamValue(fbCommand, "@GUIDExtern", FbDbType.VarChar, guidExtern);
                Helper.SetParamValue(fbCommand, "@LastName", FbDbType.VarChar, ecfTableReader.GetValue <string>("LastName"));
                Helper.SetParamValue(fbCommand, "@FirstName", FbDbType.VarChar, ecfTableReader.GetValue <string>("FirstName"));
                Helper.SetParamValue(fbCommand, "@Salutation", FbDbType.VarChar, ValueConvert.Salutation(ecfTableReader.GetValue <string>("Salutation")));
                Helper.SetParamValue(fbCommand, "@AddressLines", FbDbType.VarChar, ecfTableReader.GetValue <string>("AddressLines"));
                Helper.SetParamValue(fbCommand, "@Country", FbDbType.VarChar, ecfTableReader.GetValue <string>("CountryId"));
                Helper.SetParamValue(fbCommand, "@PostalCode", FbDbType.VarChar, ecfTableReader.GetValue <string>("PostalCode"));
                Helper.SetParamValue(fbCommand, "@Locality", FbDbType.VarChar, ecfTableReader.GetValue <string>("Locality"));
                Helper.SetParamValue(fbCommand, "@Email", FbDbType.VarChar, ecfTableReader.GetValue <string>("Email"));
                Helper.SetParamValue(fbCommand, "@HomePhoneNumber", FbDbType.VarChar, ecfTableReader.GetValue <string>("HomePhoneNumber"));
                Helper.SetParamValue(fbCommand, "@OfficePhoneNumber", FbDbType.VarChar, ecfTableReader.GetValue <string>("OfficePhoneNumber"));
                Helper.SetParamValue(fbCommand, "@Status2", FbDbType.SmallInt, StatusType.Active);


                // Status

                success = await fbCommand.ExecuteNonQueryAsync();

                await fbTransaction.CommitAsync();
            }
            catch (Exception e)
            {
                fbTransaction.Rollback();
                Console.WriteLine($"[INSERT ERROR] [Sorgeberechtigte] {e.Message}");
            }


            return(success > 0);
        }
Ejemplo n.º 10
0
        public async Task EntryExistsAsync_ForNonexistentElement_ReturnsFalse()
        {
            var audio = new AudioBuilder().WithId(GuidFactory.MakeFromInt(0)).Build();

            var dbContextMock         = new DbContextMock <ApplicationDbContext>(DummyDbOptions);
            var audioEntriesDbSetMock = dbContextMock.CreateDbSetMock(x => x.AudioEntries, new[] { audio });

            var sut = new SqlAudioEntriesRepository(dbContextMock.Object);

            var actual = await sut.EntryExistsAsync(GuidFactory.MakeFromInt(1), CancellationToken.None);

            actual.Should().BeFalse();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Messages are enqueued and delivered after the current message have been processed.
        /// </summary>
        /// <param name="message">message to send</param>
        /// <returns>task</returns>
        public Task ReplyAsync(Message message)
        {
            if (message.CorrelationId == Guid.Empty)
            {
                message.CorrelationId = MessageId;
            }
            if (message.MessageId == Guid.Empty)
            {
                message.MessageId = GuidFactory.Create();
            }

            _outboundMessages.Add(message);
            return(Task.FromResult <object>(null));
        }
Ejemplo n.º 12
0
        public static async Task <DbResult> SchoolClass(FbConnection fbConnection, EcfTableReader ecfTableReader, int tenantId)
        {
            var  id         = -1;
            Guid guidExtern = GuidFactory.Create(GuidFactory.DnsNamespace, ecfTableReader.GetValue <string>("FederationId"));

            var sql =
                "INSERT INTO \"Klassen\" " +
                "(" +
                "  \"Mandant\", \"Kuerzel\", \"KuerzelStatistik\", \"Langname1\", \"Langname2\", " +
                "  \"GUIDExtern\", \"Schulform\", \"Klassenart\", \"Notenart\" " +
                ") " +
                "VALUES ( " +
                "  @TenantId, @Code, @StatisticalCode, @Name1, @Name2, " +
                "  @GUIDExtern, @SchoolCategoryId, @SchoolClassTypeId, @GradeSystemId" +
                ") RETURNING ID";

            using var fbTransaction = fbConnection.BeginTransaction();
            try
            {
                using var fbCommand = new FbCommand(sql, fbConnection, fbTransaction);

                Helper.SetParamValue(fbCommand, "@TenantId", FbDbType.BigInt, tenantId);
                Helper.SetParamValue(fbCommand, "@Code", FbDbType.VarChar, ecfTableReader.GetValue <string>("Code"));
                Helper.SetParamValue(fbCommand, "@StatisticalCode", FbDbType.VarChar, ecfTableReader.GetValue <string>("StatisticalCode"));
                Helper.SetParamValue(fbCommand, "@Name1", FbDbType.VarChar, ecfTableReader.GetValue <string>("Name1"));
                Helper.SetParamValue(fbCommand, "@Name2", FbDbType.VarChar, ecfTableReader.GetValue <string>("Name2"));
                Helper.SetParamValue(fbCommand, "@GUIDExtern", FbDbType.Guid, guidExtern);
                Helper.SetParamValue(fbCommand, "@SchoolCategoryId", FbDbType.VarChar, ecfTableReader.GetValue <string>("SchoolCategoryId"));
                Helper.SetParamValue(fbCommand, "@SchoolClassTypeId", FbDbType.SmallInt, ecfTableReader.GetValue <string>("SchoolClassTypeId"));
                Helper.SetParamValue(fbCommand, "@GradeSystemId", FbDbType.SmallInt, ValueConvert.GradeSystem(ecfTableReader.GetValue <string>("GradeSystemId")));
                FbParameter IdParam = fbCommand.Parameters.Add("@ClassId", FbDbType.Integer, Int32.MaxValue, "ID");
                IdParam.Direction = ParameterDirection.Output;

                id = (int)await fbCommand.ExecuteScalarAsync();

                await fbTransaction.CommitAsync();

                return(new DbResult(true, id));
            }
            catch (Exception e)
            {
                await fbTransaction.RollbackAsync();

                Console.WriteLine($"[INSERT ERROR] [Klassen] {e.Message}");
                return(new DbResult(false, id));
            }
        }
Ejemplo n.º 13
0
        public async Task CountAsync_ForMultipleEntries_CountAsExpected()
        {
            var audios = new[]
            {
                new AudioBuilder().WithId(GuidFactory.MakeFromInt(0)).Build(),
                new AudioBuilder().WithId(GuidFactory.MakeFromInt(1)).Build(),
            };

            var dbContextMock         = new DbContextMock <ApplicationDbContext>(DummyDbOptions);
            var audioEntriesDbSetMock = dbContextMock.CreateDbSetMock(x => x.AudioEntries, audios);

            var sut = new SqlAudioEntriesRepository(dbContextMock.Object);

            var actual = await sut.CountAsync(CancellationToken.None);

            actual.Should().Be(2);
        }
Ejemplo n.º 14
0
        public async Task GetRangeAsync_ReturnsExpectedNbOfElemnets()
        {
            var audios = new[]
            {
                new AudioBuilder().WithId(GuidFactory.MakeFromInt(0)).Build(),
                new AudioBuilder().WithId(GuidFactory.MakeFromInt(1)).Build(),
                new AudioBuilder().WithId(GuidFactory.MakeFromInt(2)).Build(),
                new AudioBuilder().WithId(GuidFactory.MakeFromInt(3)).Build(),
            };

            var dbContextMock         = new DbContextMock <ApplicationDbContext>(DummyDbOptions);
            var audioEntriesDbSetMock = dbContextMock.CreateDbSetMock(x => x.AudioEntries, audios);

            var sut = new SqlAudioEntriesRepository(dbContextMock.Object);

            var actual = await sut.GetRangeAsync(1, 2, CancellationToken.None);

            actual.Should().HaveCount(2);
        }
Ejemplo n.º 15
0
        public static async Task <bool> SchoolClassTerm(FbConnection fbConnection, int tenantId, int classId, int termId, string classTermId,
                                                        EcfTableReader ecfTableReader)
        {
            Guid guidExtern = GuidFactory.Create(GuidFactory.DnsNamespace, classTermId);

            var success = 0;
            var sql     =
                "INSERT INTO \"KlassenZeitraeume\" " +
                "(" +
                "  \"Mandant\", \"Klasse\", \"Zeitraum\", \"GUIDExtern\", " +
                "  \"Jahrgang\" " +
                ") " +
                "VALUES ( " +
                "  @TenantId, @ClassId, @TermId, @GUIDExtern, @SchoolClassYear " +
                ")";

            using var fbTransaction = fbConnection.BeginTransaction();
            try
            {
                using var fbCommand = new FbCommand(sql, fbConnection, fbTransaction);

                Helper.SetParamValue(fbCommand, "@TenantId", FbDbType.BigInt, tenantId);
                Helper.SetParamValue(fbCommand, "@ClassId", FbDbType.BigInt, classId);
                Helper.SetParamValue(fbCommand, "@TermId", FbDbType.BigInt, termId);
                Helper.SetParamValue(fbCommand, "@GUIDExtern", FbDbType.Guid, guidExtern);
                Helper.SetParamValue(fbCommand, "@SchoolClassYear", FbDbType.SmallInt, ecfTableReader.GetValue <string>("SchoolClassYear"));

                success = await fbCommand.ExecuteNonQueryAsync();

                await fbTransaction.CommitAsync();
            }
            catch (Exception e)
            {
                fbTransaction.Rollback();
                Console.WriteLine($"[INSERT ERROR] [KlassenZeitraeume] {e.Message}");
            }


            return(success > 0);
        }
Ejemplo n.º 16
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="TcpChannel" /> class.
        /// </summary>
        /// <param name="readBuffer">Buffer used for our reading.</param>
        /// <param name="encoder">Used to encode messages before they are put in the MicroMessage body of outbound messages.</param>
        /// <param name="decoder">
        ///     Used to decode the body of incoming MicroMessages. The <c>MessageReceived</c> delegate will be
        ///     overridden by this class.
        /// </param>
        public TcpChannel(IBufferSlice readBuffer, IMessageEncoder encoder, IMessageDecoder decoder)
        {
            IsConnected = false;
            if (readBuffer == null)
            {
                throw new ArgumentNullException("readBuffer");
            }
            if (encoder == null)
            {
                throw new ArgumentNullException("encoder");
            }
            if (decoder == null)
            {
                throw new ArgumentNullException("decoder");
            }

            _readArgs = new SocketAsyncEventArgs();
            _readArgs.SetBuffer(readBuffer.Buffer, readBuffer.Offset, readBuffer.Capacity);
            _readArgs.Completed += OnReadCompleted;
            _readArgsWrapper     = new SocketAsyncEventArgsWrapper(_readArgs);

            _encoder = encoder;
            _decoder = decoder;
            _decoder.MessageReceived = OnMessageReceived;

            _writeArgs            = new SocketAsyncEventArgs();
            _writeArgs.Completed += OnSendCompleted;
            _writeArgsWrapper     = new SocketAsyncEventArgsWrapper(_writeArgs);

            _sendCompleteAction = (channel, message) => { };
            _disconnectAction   = (channel, exception) => { };
            ChannelFailure      = (channel, error) => HandleRemoteDisconnect(SocketError.ProtocolNotSupported, error);

            RemoteEndpoint = EmptyEndpoint.Instance;
            ChannelId      = GuidFactory.Create().ToString();
            Data           = new ChannelData();
        }
Ejemplo n.º 17
0
 public static Guid Generate(this Guid guid)
 {
     return(GuidFactory.NewGuid());
 }
Ejemplo n.º 18
0
 public ExampleDto()
 {
     this.Id = GuidFactory.NewGuid();
 }
Ejemplo n.º 19
0
 public AudioBuilder WithId(int audioId)
 {
     _audioId = GuidFactory.MakeFromInt(audioId);
     return(this);
 }
 protected TenantFKAuditedRecordStatedTimestampedGuidIdEntityBase()
 {
     this.Id = GuidFactory.NewGuid();
 }
Ejemplo n.º 21
0
 protected BaseCommand()
 {
     Sequence = GuidFactory.Create()
                .ToString();
 }
 // Note than although this model is not persisted in
 // a datastore, an Id is still required, as it is expressed
 // via OData.
 public ConfigurationTestStepSummary()
 {
     this.Id = GuidFactory.NewGuid();
 }
 protected UntenantedAuditedRecordStatedTimestampedGuidIdReferenceDataEntityBase()
 {
     Id = GuidFactory.NewGuid();
 }
 public SecurityProfileRoleDto()
 {
     this.Id = GuidFactory.NewGuid();
 }
Ejemplo n.º 25
0
        public static async Task <DbResult> Student(FbConnection fbConnection, EcfTableReader ecfTableReader, int tenantId)
        {
            Guid guidExtern = GuidFactory.Create(GuidFactory.DnsNamespace, ecfTableReader.GetValue <string>("Id"));

            var id  = -1;
            var sql =
                "INSERT INTO \"Schueler\" " +
                "(" +
                "  \"Mandant\", \"GUIDExtern\", \"Status\", \"Anrede\", \"Nachname\", \"Vorname\", \"Geschlecht\", " +
                "  \"Geburtsdatum\", \"Strasse\", \"PLZ\", \"Ort\", \"Gemeinde\", \"EMail\", \"Telefon\", \"Mobil\", " +
                "  \"Staatsangeh1\", \"Staatsangeh2\", \"Verkehrssprache\", \"Konfession\", \"Krankenkasse\", \"ZugangAm\", " +
                "  \"Grundschuleintritt\" " +
                ") " +
                "VALUES ( " +
                "  @TenantId, @GUIDExtern, @Status, @Salutation, @LastName, @FirstName, @Gender, " +
                "  @Birthdate, @AddressLines, @PostalCode, @Locality, @Region, @Email, @HomePhoneNumber, @MobileNumber, " +
                "  @Nationality1, @Nationality2, @NativeLanguage, @Religion, @HealthInsuranceProvider, @EntryDate, " +
                "  @FirstEntryDate " +
                ") RETURNING ID";


            using var fbTransaction = fbConnection.BeginTransaction();
            try
            {
                using var fbCommand = new FbCommand(sql, fbConnection, fbTransaction);

                Helper.SetParamValue(fbCommand, "@TenantId", FbDbType.Integer, tenantId);
                Helper.SetParamValue(fbCommand, "@GUIDExtern", FbDbType.VarChar, guidExtern);
                Helper.SetParamValue(fbCommand, "@Status", FbDbType.SmallInt, 2);
                Helper.SetParamValue(fbCommand, "@Salutation", FbDbType.VarChar, ValueConvert.Salutation(ecfTableReader.GetValue <string>("Salutation")));
                Helper.SetParamValue(fbCommand, "@LastName", FbDbType.VarChar, ecfTableReader.GetValue <string>("LastName"));
                Helper.SetParamValue(fbCommand, "@FirstName", FbDbType.VarChar, ecfTableReader.GetValue <string>("FirstName"));
                Helper.SetParamValue(fbCommand, "@Gender", FbDbType.VarChar, ValueConvert.Gender(ecfTableReader.GetValue <string>("Gender")));
                Helper.SetParamValue(fbCommand, "@Birthdate", FbDbType.Date, ecfTableReader.GetValue <string>("Birthdate"));
                Helper.SetParamValue(fbCommand, "@AddressLines", FbDbType.VarChar, ecfTableReader.GetValue <string>("AddressLines"));
                Helper.SetParamValue(fbCommand, "@PostalCode", FbDbType.VarChar, ecfTableReader.GetValue <string>("PostalCode"));
                Helper.SetParamValue(fbCommand, "@Locality", FbDbType.VarChar, ecfTableReader.GetValue <string>("Locality"));
                Helper.SetParamValue(fbCommand, "@Region", FbDbType.VarChar, ecfTableReader.GetValue <string>("RegionId"));
                Helper.SetParamValue(fbCommand, "@Email", FbDbType.VarChar, ecfTableReader.GetValue <string>("Email"));
                Helper.SetParamValue(fbCommand, "@HomePhoneNumber", FbDbType.VarChar, ecfTableReader.GetValue <string>("HomePhoneNumber"));
                Helper.SetParamValue(fbCommand, "@MobileNumber", FbDbType.VarChar, ecfTableReader.GetValue <string>("MobileNumber"));
                Helper.SetParamValue(fbCommand, "@Nationality1", FbDbType.VarChar, ecfTableReader.GetValue <string>("Nationality1Id"));
                Helper.SetParamValue(fbCommand, "@Nationality2", FbDbType.VarChar, ecfTableReader.GetValue <string>("Nationality2Id"));
                Helper.SetParamValue(fbCommand, "@NativeLanguage", FbDbType.VarChar, ecfTableReader.GetValue <string>("NativeLanguage"));
                Helper.SetParamValue(fbCommand, "@Religion", FbDbType.VarChar, ecfTableReader.GetValue <string>("ReligionId"));
                Helper.SetParamValue(fbCommand, "@HealthInsuranceProvider", FbDbType.VarChar, ecfTableReader.GetValue <string>("HealthInsuranceProvider"));
                Helper.SetParamValue(fbCommand, "@EntryDate", FbDbType.Date, ecfTableReader.GetValue <string>("EntryDate"));
                Helper.SetParamValue(fbCommand, "@FirstEntryDate", FbDbType.Date, ecfTableReader.GetValue <string>("FirstEntryDate"));

                FbParameter IdParam = fbCommand.Parameters.Add("@Id", FbDbType.Integer, Int32.MaxValue, "ID");
                IdParam.Direction = ParameterDirection.Output;

                id = (int)await fbCommand.ExecuteScalarAsync();

                await fbTransaction.CommitAsync();

                return(new DbResult(true, id));
            }
            catch (Exception e)
            {
                fbTransaction.Rollback();
                Console.WriteLine($"[INSERT ERROR] [Schueler] {e.Message}");
                return(new DbResult(false, id));
            }
        }
 public AudioPlaylistsBuilder WithPlaylistId(int playlistId)
 {
     _playlistId = GuidFactory.MakeFromInt(playlistId);
     return(this);
 }
Ejemplo n.º 27
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="EfAggregateMemento" /> class.
 /// </summary>
 protected EfAggregateMemento()
 {
     SnapshotId = GuidFactory.NewGuidComb();
 }
 // Note than although this model is not persisted in
 // a datastore, an Id is still required, as it is expressed
 // via OData.
 public ConfigurationStepRecord()
 {
     this.Id = GuidFactory.NewGuid();
 }
Ejemplo n.º 29
0
 public IdentityProvider()
 {
     GuidFactory.NewGuid();
 }
Ejemplo n.º 30
0
 public SecurityProfilePermissionDto()
 {
     this.Id = GuidFactory.NewGuid();
 }
 protected TenantedRecordStateGuidIdDtoBase()
 {
     this.Id = GuidFactory.NewGuid();
 }