Create fake but realistic data for your demo and presentation

Frank Boucher ☁ - May 24 '23 - - Dev Community

In preparation for a demo in his talk, Leon Welicki needed "safe data", meaning data that looks legit but is fake. This post shares how I use Azure SQL Database templates, ChatGTP, and the .NET package Bogus to create data safe to be used, random, but that fits the demo theme and requirement.

Don't miss this awesome demo!

Watch Leon's session: Full stack scale with the Microsoft Power Platform on the Microsoft Build website.

The Context

Leon needs some sales data for his demo: salespeople, and a history of transactions that cover a year. The data need to be random but fit the demo theme and requirement.

Part 1: Azure SQL Database Template

When thinking about a sales database, my first stop is most of the time AdventureWorks. It's one of those fake companies created by Microsoft to illustrate many different scenarios. This is great because it's completely clean data and it's free to use. There are many ways to create the database locally but I decided to use Azure SQL Database template.

In the Azure Portal, when creating a new Azure SQL Database, you can specify the AdventureWorks sample in the section "Additional settings". And after a few minutes, you will have your version of AdventureWorks ready.

Option button to use existing sample when creating a SQL database from the Azure portal

After creating a table that contains only the fields I needed, I wrote a query to fill it using the existing customer table. I then create a script so it could be easily created as many times as needed.

That was a great start! However there wasn't enough transaction in the database to cover one year, and the products are a perfect match for our theme: telecom. Time to change tools

Part 2: ChatGPT

Creating products was the next logical task, I needed products in order to create transactions. I had a few ideas for telecom products, but not fifty! This is when I thought I was to ask a good friend of mine... ChatGPT! I asked ChatGPT: Create 55 telecom products (id, name, price) and return it as a List in C#. And just like that, I had my fifty-five products.

the prompt and it's response on chatGPT website

Everything was going so well! I already had many salespeople and telecom products. It was time to create the transactions.

Part 3: Bogus

When creating applications we often need fake data for our tests. As a .NET developer, there was a package I heard about that I was looking forward to trying and this was the perfect occasion. Bogus is a simple fake data generator for .NET languages. Bogus can be added to your project using NuGet.

You create rules that define how the data should look and then you generate as much data as you need. Here is an example of a rule that creates a transaction:

using Bogus;
using System.Text;

var salesTeam = Tools.GetSalesTeam();
var products = Tools.GetProducts();
var commissions = Tools.GetCommission();
var status = new List<string>{"Paid","Processing" , "Pending"};

var transactionGenerator = new Faker<Transaction>()
                                .RuleFor(t => t.Id, f => f.Random.Number(1000, 999999))
                                .RuleFor(t => t.Status, f => f.PickRandom(status))
                                .RuleFor(t => t.Date, f => f.Date.Between(DateTime.Parse("2022-01-01"), DateTime.Parse("2023-04-30")))
                                .RuleFor(t => t.Seller, f => f.PickRandom(salesTeam))
                                .RuleFor(t => t.Quantity, f => f.Random.Number(1, 5))
                                .RuleFor(t => t.Product, f => f.PickRandom(products))
                                .RuleFor(t => t.Commission, f => f.PickRandom(commissions))
                                .RuleFor(t => t.Total, (f, t) => (t.Quantity * t.Product.Price) - ((t.Quantity * t.Product.Price) * (t.Commission.Value / 100)))
                            ;

var history = transactionGenerator.Generate(1000);
Enter fullscreen mode Exit fullscreen mode

With a few lines of code, I was able to generate thousands of unique transactions. All of them had a unique ID and a set of random values based on subsets that I had created before: seller information, product names and price, status, etc.

Then the only thing was to save the data in an Excel file and send it to Leon.

Conclusion

This was a fun project! Thanks to all those tools, I was able to create all the data we needed in just a few hours. This file will be used as starting point during Leon's presentation: Full stack scale with the Microsoft Power Platform. To learn what he will be doing with it, make sure to not miss it!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player